sql function with empty row - Mailing list pgsql-general

From Philipp Kraus
Subject sql function with empty row
Date
Msg-id A5624A8E-1E70-49BC-9CBB-798AE6F8276F@tu-clausthal.de
Whole thread Raw
Responses Re: sql function with empty row
Re: sql function with empty row
Re: sql function with empty row
Re: sql function with empty row
List pgsql-general
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.

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



pgsql-general by date:

Previous
From: Michael Paquier
Date:
Subject: Re: Out of memory error with PG10.3, 10.4 but not 9.3.19
Next
From: Adrian Klaver
Date:
Subject: Re: sql function with empty row