| From: | "Guy Rouillier" <guyr(at)masergy(dot)com> | 
|---|---|
| To: | "PostgreSQL General" <pgsql-general(at)postgresql(dot)org> | 
| Subject: | Re: Pgsql dynamic statements and null values | 
| Date: | 2005-03-09 19:13:41 | 
| Message-ID: | CC1CF380F4D70844B01D45982E671B2348E6C2@mtxexch01.add0.masergy.com | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-general | 
Ragnar Hafstað wrote:
> On Tue, 2005-03-08 at 16:30 -0600, Guy Rouillier wrote:
>> We use a dynamic statement in a pgsql stored function to insert rows
>> into a table determined at run time.  After much debugging, I've
>> discovered that a null incoming argument will cause the dynamic
>> statement to evaluate to null.  The error message emitted is "unable
>> to execute null statement."
> 
> can't you use COALESCE() ?
Thanks Ragnar and Martijn for the replies. NULLIF doesn't seem applicable here as I already have a null value coming in, so I'm not comparing it to anything. I had tried COALESCE before my original post and it produced the same result: cannot execute null statement. However, your prompting motivated me to try a couple more alternatives. Of the many I tried, here is one that works:
coalesce(quote_literal(inval), 'NULL')
Nice to know, but given the verbosity, I think I'll stick with my check_null(inval). A worthwhile exercise, though, since I can now reduce that function to this one line.
-- 
Guy Rouillier
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Joshua D. Drake | 2005-03-09 19:21:06 | Re: partitionning | 
| Previous Message | Mican Bican | 2005-03-09 19:08:01 | Re: java is locked when select for update |