pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedReceive a record not a tuple - plpgsql
2+ messages / 2 participants
[nested] [flat]
* Receive a record not a tuple - plpgsql
@ 2005-11-16 20:21 Flávio Brito <flavio@gral.org.br>
0 siblings, 1 reply; 2+ messages in thread
From: Flávio Brito @ 2005-11-16 20:21 UTC (permalink / raw)
To: pgsql-admin
Dear Friends
How can I call a function into a function? My problem is: I'm trying to
calculate a tax(inss) over a employer 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();
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Receive a record not a tuple - plpgsql
@ 2005-11-21 04:42 Thomas F. O'Connell <tfo@sitening.com>
parent: Flávio Brito <flavio@gral.org.br>
0 siblings, 0 replies; 2+ messages in thread
From: Thomas F. O'Connell @ 2005-11-21 04:42 UTC (permalink / raw)
To: Flávio Brito <flavio@gral.org.br>; +Cc: pgsql-admin
On Nov 16, 2005, at 2:21 PM, Flávio Brito wrote:
> How can I call a function into a function? My problem is: I'm
> trying to calculate a tax(inss) over a employer 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?
Have you looked into set-returning functions? It seems like that
might be what you're looking for:
http://www.postgresql.org/docs/8.1/static/plpgsql-control-
structures.html#PLPGSQL-STATEMENTS-RETURNING
--
Thomas F. O'Connell
Database Architecture and Programming
Co-Founder
Sitening, LLC
http://www.sitening.com/
110 30th Avenue North, Suite 6
Nashville, TN 37203-6320
615-469-5150
615-469-5151 (fax)
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2005-11-21 04:42 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-11-16 20:21 Receive a record not a tuple - plpgsql Flávio Brito <flavio@gral.org.br>
2005-11-21 04:42 ` Thomas F. O'Connell <tfo@sitening.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox