Re: How do I check for NULL

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Igor Korot <ikorot01(at)gmail(dot)com>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: How do I check for NULL
Date: 2025-12-09 16:09:51
Message-ID: 2d6f7410-433e-48a6-85b5-dd29d12bcf61@aklaver.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 12/8/25 23:53, Igor Korot wrote:
> Hi, Davd,
>
> On Mon, Dec 8, 2025 at 6:44 PM David G. Johnston
> <david(dot)g(dot)johnston(at)gmail(dot)com> wrote:
>>
>> On Monday, December 8, 2025, Igor Korot <ikorot01(at)gmail(dot)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>
>>

Read:

https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS

>
> Thank you.
>>
>> David J.
>>
>
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Thiemo Kellner 2025-12-09 17:14:27 How do I check for NULL
Previous Message David G. Johnston 2025-12-09 13:43:57 Re: How do I check for NULL