Re: sql function with empty row
От | Adrian Klaver |
---|---|
Тема | Re: sql function with empty row |
Дата | |
Msg-id | e57b0979-e0e0-32a7-2c81-7455b6910cc8@aklaver.com обсуждение исходный текст |
Ответ на | sql function with empty row (Philipp Kraus <philipp.kraus@tu-clausthal.de>) |
Список | pgsql-general |
On 05/16/2018 11:07 AM, Philipp Kraus wrote: > Hello, > > I have defined a SQL function > > CREATE OR REPLACE FUNCTION substancetrivialname(text) > RETURNS substance > LANGUAGE 'sql' > COST 100 > VOLATILE > AS $BODY$ > select s.* from substancetrivialname n > join substance s on s.id = n.idsubstance > where lower(btrim(n.name)) = lower(btrim($1)); > $BODY$; > > substance and substancetrivialname have got a 1-to-N relationship (for each substance can exist multiple trivial names). > If I call the function with a non-existing trivial name it returns a single row with all fields are set to NULL. Since there can be many trivial names per substance shouldn't you be using SETOF?: https://www.postgresql.org/docs/10/static/xfunc-sql.html#XFUNC-SQL-FUNCTIONS-RETURNING-SET > > If I run the join query directly it returns an empty record set on a non-existing trivial name. > I expected equal behavior on my function, so my question is, how can I fix this? > > Thanks > > Phil > > > -- Adrian Klaver adrian.klaver@aklaver.com
В списке pgsql-general по дате отправления: