Re: How can I create null value from function call with no results? - Mailing list pgsql-general

From Seref Arikan
Subject Re: How can I create null value from function call with no results?
Date
Msg-id CA+4ThdrghtXyxk=yCcUCGxA97dESrePU4FDrC0puk3Vu9q4O+g@mail.gmail.com
Whole thread Raw
In response to Re: How can I create null value from function call with no results?  (David G Johnston <david.g.johnston@gmail.com>)
List pgsql-general
Hi David,
Thanks for the feedback. I've actually tried to do what you've suggested, but I always found myself unable to do the check for empty result for query in an elegant way.
That is, I end up thinking about creating a temp table to put the query results in (which can be > 1), then check if the temp table is empty and return Null if that is the case.

Your response reads as if there is a more elegant way of doing this, could you write down a dummy version of the alternative to return query you're suggesting?

Kind regards
Seref

Ps: sorry for the double post David


On Wed, Jul 30, 2014 at 7:26 PM, David G Johnston <david.g.johnston@gmail.com> wrote:
Seref Arikan wrote
> select 1,test_empty_row(1);

SELECT 1, (SELECT test_empty_row(1)) AS func_result

You can also adjust the function to either return the result of the query OR
"RETURN NULL" if no results were found.  i.e., do not use "RETURN QUERY"

David J.





--
View this message in context: http://postgresql.1045698.n5.nabble.com/How-can-I-create-null-value-from-function-call-with-no-results-tp5813311p5813313.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

pgsql-general by date:

Previous
From: Scott Marlowe
Date:
Subject: Re: free RAM not being used for page cache
Next
From: Seref Arikan
Date:
Subject: Re: How can I create null value from function call with no results?