Postgres noobie here.
I am trying to convert a SQL Server stored process to a Postgres function. It is currently not possible to figure out how to include this SQL string in Postgres.
SQL Server:
input: @name = null SELECT * FROM table WHERE name = ISNULL(@name, name)
Postgres:
input: n = null SELECT * FROM table WHERE name = COALESCE(n, name)
I get the error "column n does not exist". How to refer to parameters in select statements in Postgres functions?
UPDATE:
Postgres Function Definition
CREATE OR REPLACE FUNCTION fn_name (n VARCHAR(32) = NULL, name OUT varchar(32), description OUT varchar(64)) RETURNS setof record AS $$ SELECT u.name , u.description FROM table_a u WHERE u.name = COALESCE(n, u.name); $$ LANGUAGE sql;
Nick vaccaro
source share