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