KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Postgres noobie here. I'm trying to convert a SQL Server stored proc into a Postgres function. Currently cannot figure out how to turn this SQL line into 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'm getting the error "column n does not exist." How do I reference parameters in select statements in Postgres functions? UPDATE: Definition of Postgres function 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;
Tags (comma-separated)
Save Edits
Cancel