Return entire row : Function Return « Store Procedure Function « PostgreSQL





Return entire row


postgres=#
postgres=# CREATE TABLE emp (
postgres(#    name        text,
postgres(#    salary      numeric,
postgres(#    age         integer,
postgres(#    cubicle     point
postgres(# );
CREATE TABLE
postgres=#
postgres=#
postgres=# insert into emp values ('None', 1000.0, 25, '(2,2)');
INSERT 0 1
postgres=#
postgres=# CREATE FUNCTION new_emp() RETURNS emp AS $$
postgres$#    SELECT ROW('None', 1000.0, 25, '(2,2)')::emp;
postgres$# $$ LANGUAGE SQL;
CREATE FUNCTION
postgres=#
postgres=# select new_emp();
         new_emp
--------------------------
 (None,1000.0,25,"(2,2)")
(1 row)

postgres=#
postgres=# drop function new_emp();
DROP FUNCTION
postgres=# drop table emp;
DROP TABLE
postgres=#
postgres=# \
           
       










Related examples in the same category

1.Define function to add two parameters together
2.Using the result set returned from the function
3.Returning a concatenated string
4.Return 'double' from function
5.A SQL function that returns a book title based on the ID number passed to the function
6.Return a table from a function