Re: How do I check for NULL - Mailing list pgsql-general

From David G. Johnston
Subject Re: How do I check for NULL
Date
Msg-id CAKFQuwZeOqHpV4jpRWQPzfCPnM7Asz9t11+L2Fd=7UA2kTaGNA@mail.gmail.com
Whole thread Raw
In response to Re: How do I check for NULL  (Igor Korot <ikorot01@gmail.com>)
List pgsql-general

Tuesday, December 9, 2025, Igor Korot <ikorot01@gmail.com> wrote:
Hi, Davd,

On Mon, Dec 8, 2025 at 6:44 PM David G. Johnston
<david.g.johnston@gmail.com> wrote:
>
> On Monday, December 8, 2025, Igor Korot <ikorot01@gmail.com> wrote:
>>
>>
>> However,, I'd like to still insert the record and I'd like to do something like:
>>
>> INSERT INTO test VALUES( 0, 'abc', 12345, IF( (SELECT foo FROM bar) ==
>> NULL, "postgres", <select_result>), /*more data follow*/);
>>
>> What would be the best way to achieve this?
>
>
> The “coalesce” function.

This is the query I use for my ODBC calls:

            qry2 = L"INSERT INTO \"test\" VALUES( ?, ?, (SELECT c.oid
FROM pg_class c, pg_namespace nc WHERE nc.oid = c.relnamespace AND
c.relname = ? AND nc.nspname = ?), COALESCE((SELECT tableowner FROM
pg_tables WHERE tablename = ? AND schemaname = ?), \"postgres\"), ...)
ON CONFLICT DO NOTHING;";

Calling SQLExecute after parameter binding results in

"L"ERROR: column \"postgres\" does not exist;\nError while preparing
parameters"std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>


Use single quotes for a string literal value.

David J.
 

pgsql-general by date:

Previous
From: Igor Korot
Date:
Subject: Re: How do I check for NULL
Next
From: Adrian Klaver
Date:
Subject: Re: How do I check for NULL