Re: Receive a record not a tuple - plpgsql

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Flávio Brito <flavio(at)gral(dot)org(dot)br>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Receive a record not a tuple - plpgsql
Date: 2005-11-17 04:14:56
Message-ID: 20051117041456.GA63985@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Wed, Nov 16, 2005 at 06:41:36PM -0200, Flvio Brito wrote:
> 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?

You can put a function in the FROM clause and use a column definition
list:

test=> SELECT test();
test
----------------
(1,Mary,32.45)
(1 row)

test=> SELECT * FROM test() AS (id integer, name text, salary numeric);
id | name | salary
----+------+--------
1 | Mary | 32.45
(1 row)

Another possibility is to create a type and have the function return
that type instead of record:

CREATE TYPE person_info AS (
id integer,
name text,
salary numeric
);

CREATE FUNCTION test() RETURNS person_info AS ...

test=> SELECT * FROM test();
id | name | salary
----+------+--------
1 | Mary | 32.45
(1 row)

test=> SELECT (test()).*;
id | name | salary
----+------+--------
1 | Mary | 32.45
(1 row)

Is one of these examples what you're looking for?

--
Michael Fuhr

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Emiliano Amilcarelli 2005-11-17 07:54:44 plpython integer types
Previous Message ryan miller 2005-11-16 23:02:04 pg_connect works, DBI::connect says permission denied