pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Flávio Brito <flavio@gral.org.br>
To: pgsql-admin@postgresql.org
Subject: Receive a record not a tuple - plpgsql
Date: Wed, 16 Nov 2005 18:21:31 -0200
Message-ID: <1132172491.26344.13.camel@localhost> (raw)

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();

view thread (2+ messages)  latest in thread

Message-ID: <1132172491.26344.13.camel@localhost>
Permalink:  ../1132172491.26344.13.camel@localhost/
Also on:    postgresql.org/message-id/1132172491.26344.13.camel@localhost

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: flavio@gral.org.br
  Subject: Re: Receive a record not a tuple - plpgsql
  In-Reply-To: <1132172491.26344.13.camel@localhost>
  References: <1132172491.26344.13.camel@localhost>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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