From: | Flávio Brito <flavio(at)gral(dot)org(dot)br> |
---|---|
To: | pgsql-novice(at)postgresql(dot)org |
Subject: | Receive a record not a tuple - plpgsql |
Date: | 2005-11-16 20:41:36 |
Message-ID: | 1132173696.1442.1.camel@localhost |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
Dear Friends
How can I call a function into a function? My problem is: I'm trying to
calculate a tax(inss) over a employee salary. I created a function
called inss that do it correctly, but when I create another one to show
more attributes (inss is not a attribute, it is calculate over a salary)
I receive a record (like {1,Mary,32.45} not a tuple. How can I solve it?
CREATE TABLE emp
(
cod numeric
name text NOT NULL,
last_date timestamp,
last_user text,
salary numeric,
CONSTRAINT pkey PRIMARY KEY (cod)
)
CREATE FUNCTION inss() RETURNS numeric AS '
SELECT salary*0.11 FROM emp;
'LANGUAGE 'sql';
---------------------------------------------------------------------------------------------
It is OK
---------------------------------------------------------------------------------------------
CREATE OR REPLACE FUNCTION mostra_inss() RETURNS setof record AS '
select name, inss(), salary from emp;
'LANGUAGE 'sql';
---------------------------------------------------------------------------------------------
--- Only for test --- DROP FUNCTION show_inss();
--- Only for test --- select inss();
---------------------------------------------------------------------------------------------
--- Another Test - Not OK
CREATE OR REPLACE FUNCTION show_inss() RETURNS VARCHAR AS '
DECLARE
inss float;
BEGIN
SELECT INTO inss inss() FROM emp;
RETURN inss;
END;
' LANGUAGE 'plpgsql';
---------------------------------------------------------------------------------------------
--- Another Test (NOT OK)
---------------------------------------------------------------------------------------------
create or replace function test_inss() returns record as '
DECLARE
d record;
BEGIN
for d in select name,salary,inss() from emp
loop
end loop;
RETURN;
END;
' language 'plpgsql';
select test_inss();
From | Date | Subject | |
---|---|---|---|
Next Message | Bruno Wolff III | 2005-11-16 21:12:05 | Re: Application using PostgreSQL as a back end (experienced programmers |
Previous Message | Andreas Kretschmer | 2005-11-16 20:06:05 | Re: Writing Text Files from PostgreSQL |