Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vSy0a-00AGOT-0f for pgsql-general@arkaria.postgresql.org; Tue, 09 Dec 2025 13:44:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vSy0Y-004pBF-1y for pgsql-general@arkaria.postgresql.org; Tue, 09 Dec 2025 13:44:02 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vSy0Y-004pB7-0w for pgsql-general@lists.postgresql.org; Tue, 09 Dec 2025 13:44:02 +0000 Received: from mail-oa1-x2f.google.com ([2001:4860:4864:20::2f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vSy0W-00438T-1k for pgsql-general@lists.postgresql.org; Tue, 09 Dec 2025 13:44:02 +0000 Received: by mail-oa1-x2f.google.com with SMTP id 586e51a60fabf-3f16015f484so3579261fac.1 for ; Tue, 09 Dec 2025 05:44:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765287838; x=1765892638; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=LeqtVhFo7PLpU1pQnKzxwFA5m4/19MpXRcIBmMTmp1o=; b=LbfeHD4pU3evllFmPGXRRozhY9Bs8eJ5QV4C5tOT625OOVMyWFA6h9I3Np7OdfwThu myqLknKQez4OeMcmMVH2rkH+ukTL1eEsPOiODVG/C/6qpWDMjvDBg0LAbNscjJrxBMGw wg92LUVaOceU9XyEH2X28gUpdglYZu/BSh6QdEAC9rA0TnQoz3EScJ0WCzhS32+Y79Sp ApLx34uC2hrBdmysO84GOH2ijYCRFbYToPkXFWIgLvorrc5knObMfNs2qzYLYbyJFfeb 7eRNPLs7Dq9ENC9gSvdQnqyVvkZ6VAM4SFlo6coc52uXOaI2ulK6kQ6H8FMaSM1JoloI Dg8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765287838; x=1765892638; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=LeqtVhFo7PLpU1pQnKzxwFA5m4/19MpXRcIBmMTmp1o=; b=oYgoLkGC+MHX4J47+MAZc28yyTgRk/2t7/sKsdng/qVziXhoyoOl/wJfieC9XD6MaM fZFkCms4lrVoxK8tdmec7v7LOAK+js1RDO0XnD2pvQO4a0ScTvx4kmShgVSjI3oCAOBP pJEVLxdx7E0ALV7qBp8LHytwnNu72/kYk60R8xeOOY3or3dwWwKhmz+bARENB5TL8lTz ++JcCDGCyEzavqhvsO9FUaEZA3MBd9FMoXjwgUPbplGpIh8Kgn4VbbvXWV6K6IaOpFZD r5EmJyrY4t20XyuJ1bLokOVh18fCzPE2KSdlfkLgn1eDFhUWxDHo2KoIOyuJEOyKMDl3 MJ+w== X-Gm-Message-State: AOJu0YxenF/fvD1/DXwXXLPgJBA5V1bwsbFQQRl0V8dwAaHPVL2hPYnQ a6/fllluto3nsnbAyvhiEm655ieEkv5a/lOOARdFd+xSMMDj2/LMeyRwdX23II/DcyMLkINMm2S g4ePC1O50FP1Cs6Vtr3vwHuUrVq96BmY= X-Gm-Gg: ASbGncsxuEUYJfeP8S8Ww+DHReCmCZ2CefHDOCbzbRoMvP1saBsYCQDe2HU8ySrCObi 0UzU3qcbrFfTcF1tRjD4H1AJG/hyCthZF7XNmuLIkVNkbHdP/yaI1GSTypicCsqIcvyUyv3mQC7 rTUpSUmL+eU8oNNJA3Ce9FgHVRJsYsHyyNnj3eoSKGDC6kPYUb5pRzODl0KrR5ZKJ1KvGINdDTQ +CQpUgTx7AScL3CXWjO1C0Hb/NNHvivK3uqFModxrvuqiyp+ulbTWl76+dvnf7pgLXPuQ== X-Google-Smtp-Source: AGHT+IEqinEup4iwaXsEC7vNLGtaCc/iKT9YySXby0i+LCPFAS+6jacoon4NKjFqFA69MYWnKl/A9s1PiAJ1VP2cKsI= X-Received: by 2002:a05:6820:2087:b0:656:bbd9:51d7 with SMTP id 006d021491bc7-65b237df94emr511301eaf.2.1765287838458; Tue, 09 Dec 2025 05:43:58 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a05:6802:329a:10b0:603:ff:915e with HTTP; Tue, 9 Dec 2025 05:43:57 -0800 (PST) In-Reply-To: References: From: "David G. Johnston" Date: Tue, 9 Dec 2025 06:43:57 -0700 X-Gm-Features: AQt7F2o1j0VDd_g9-7sNHyIu_nfzciOwb_3Twm8ENyRR2u_e_ZFw0FGr1O0vflQ Message-ID: Subject: Re: How do I check for NULL To: Igor Korot Cc: "pgsql-generallists.postgresql.org" Content-Type: multipart/alternative; boundary="00000000000089a9b00645851a64" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000089a9b00645851a64 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Tuesday, December 9, 2025, Igor Korot wrote: > Hi, Davd, > > On Mon, Dec 8, 2025 at 6:44=E2=80=AFPM David G. Johnston > wrote: > > > > On Monday, December 8, 2025, Igor Korot 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) = =3D=3D > >> NULL, "postgres", ), /*more data follow*/); > >> > >> What would be the best way to achieve this? > > > > > > The =E2=80=9Ccoalesce=E2=80=9D function. > > This is the query I use for my ODBC calls: > > qry2 =3D L"INSERT INTO \"test\" VALUES( ?, ?, (SELECT c.oid > FROM pg_class c, pg_namespace nc WHERE nc.oid =3D c.relnamespace AND > c.relname =3D ? AND nc.nspname =3D ?), COALESCE((SELECT tableowner FROM > pg_tables WHERE tablename =3D ? AND schemaname =3D ?), \"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::allocator > > Use single quotes for a string literal value. David J. --00000000000089a9b00645851a64 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Tuesday, December 9, 2025, Igor Korot <ikorot01@gmail.com> wrote:
david.g.johnston@gmail.co= m> 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) =3D=3D
>> NULL, "postgres", <select_result>), /*more data fo= llow*/);
>>
>> What would be the best way to achieve this?
>
>
> The =E2=80=9Ccoalesce=E2=80=9D function.

This is the query I use for my ODBC calls:

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

Calling SQLExecute after parameter binding results in

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


Use single quotes for a string literal val= ue.

David J.
=C2=A0
--00000000000089a9b00645851a64--