Pass in entire table row to a function : Create Function « Store Procedure Function « PostgreSQL






Pass in entire table row to a function


postgres=#
postgres=# CREATE TABLE emp (
postgres(#    name        text,
postgres(#    salary      numeric,
postgres(#    age         integer,
postgres(#    cubicle     point
postgres(# );
CREATE TABLE
postgres=#
postgres=#
postgres=# CREATE FUNCTION getname(emp) RETURNS text AS $$
postgres$#    SELECT $1.name;
postgres$# $$ LANGUAGE SQL;
CREATE FUNCTION
postgres=#
postgres=# SELECT getname(emp.*) from emp;
  REATE
 getname
---------
(0 rows)

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








Related examples in the same category

1.Create a simeple function
2.Case insensitive
3.Add three parameters together in a function
4.Functions with Output Parameters
5.The simplest possible SQL function has no arguments and simply returns a base type