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 1vT4VQ-00CHC0-1A for pgsql-general@arkaria.postgresql.org; Tue, 09 Dec 2025 20:40:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vT4VO-006poB-0w for pgsql-general@arkaria.postgresql.org; Tue, 09 Dec 2025 20:40:18 +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 1vT4VN-006po3-32 for pgsql-general@lists.postgresql.org; Tue, 09 Dec 2025 20:40:18 +0000 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vT4VM-0046oa-0h for pgsql-general@lists.postgresql.org; Tue, 09 Dec 2025 20:40:17 +0000 Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-b7bd8b170e0so73865266b.3 for ; Tue, 09 Dec 2025 12:40:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765312815; x=1765917615; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=ZUJgChdRZErkYEO4N1kcIks/mBMAZa3ftpgscLv9wuw=; b=HdthDOgS1e9T8USQi0398c6aBUQkDQiCeBm/OzWklLdgM4YvvD/wFRpQInmXk3q0oN xBafyZGTlCCbmetfBisMwa1dlAP9MinbNVOCjXsCgg8Yr8diQoweZqYOUrmzw4jkwYjp OMNmtTTGvoKLjS0A3F+Txa3Xybis0vff9kryRH7XJKDSIZjt3KIJx65gqd07KKlVqv5N arruzx1r+E8mfXPc6ljyRzozyicpJ1uVlnXGkHeBEiZjovgvQNBiHUdRIkn/RW2oLqT2 gxydkPvc+UprEwLu29jY5doNFs/2ZQzQ30T9AEJf+8BOY47i8Jh+k34bADzVM6wErNNT TZ6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765312815; x=1765917615; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ZUJgChdRZErkYEO4N1kcIks/mBMAZa3ftpgscLv9wuw=; b=uMy72VbkmNRuNMmZv+pUjiVrwdwYrGiiBKjifokQZtd0qW8+USRoEMhmH3fOqATmGh vyuv+p6u/aIteloErhSRi3MpNBVOjbB5xcRLlwiugPyiLwrp8ttjAIXFqCfeZkYa0RT5 Kjh89n/cHGSCidLYn3oRUzXwt6JsEey8eesIkjeO0+13CTiatfEp5HVgvBF21jgq4KNQ XQ0arw9t0suXzJN3tKYPvqK6tGZnAuFBkRgvA209nJe+T9rNLEYXgVzBWJFUVpNAFj5f O68fBtnThELF9ewL5aFCFn+KzUa3G94Wljb/CpA2l1Kqdl2CqDVzJi1v3+ZsavYwaQOE duUA== X-Gm-Message-State: AOJu0Yxeln73hMxFEW4b6FMX97B9hmP/EX9AxHNAwty4cfK7+FRfcT+9 /wRzyZV6TNBlOlHggeOBvd+0jm3Mkh76QYRGqrvj2iKOX7pCxBuygnoW0EcDw9JSE54NZz7V/cW bbSum4NxAYq8+G63WEYbTNPjeE6ja26N7gNg= X-Gm-Gg: ASbGnctFom9fDlR9cX5tUUiGKiAx65D6y/hiebtHmoQKXt5n5sorAnF1PhDmHFZnYnh 0faQFpV2RhUzqJY5pBcISTVw/l6koUNYW1RDQ2H7MBfAAI7SLd9weL8nSXs92UNWSz8RObtfkUQ fk3OVOzNKFaCbIVpEO7Pj8AYKcg8FL8L6ook/p8118XtsMsldlCizAZsXsjsKp5ctWlq6V6ADK0 zAZHQ2DZT3YOfnoS1PA3OksG30yPR4AamgGB6V+28UP/+c/XT9+gYoUGr0F9DAb3qQ= X-Google-Smtp-Source: AGHT+IHLwsTYQRKiShndeSFPwavHtxVWseohjTVv7/20G+2eQ4MpbUAs9Ygh3hfxswrq6Csis8sbVBRHvm+FwXBAMU0= X-Received: by 2002:a17:907:268e:b0:b72:3765:eda9 with SMTP id a640c23a62f3a-b7a2478d00emr1344731866b.60.1765312814850; Tue, 09 Dec 2025 12:40:14 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Juan Rodrigo Alejandro Burgos Mella Date: Tue, 9 Dec 2025 15:40:04 -0500 X-Gm-Features: AQt7F2o-8BKSJSIVLj97RbIycD2ifyIQYF7BzjHJaTaDBf3vwNesc_GjmFA-g_g Message-ID: Subject: Re: How do I check for NULL To: Igor Korot Cc: "pgsql-generallists.postgresql.org" Content-Type: multipart/alternative; boundary="0000000000003f24dc06458aeb5f" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000003f24dc06458aeb5f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Did you try setting a default value to the field? Atte JRBM El lun, 8 dic 2025 a las 21:40, Igor Korot () escribi= =C3=B3: > Hi, ALL, > Consider the following scenario: > > CREATE TABLE test(a INT, b VARCHAR(256), c INT, d VARCHAR(256), /* > more fields follows*/); > CREATE UNIQUE INDEX test_x( b, c, d ); > > Now I try to do: > > INSERT INTO test VALUES( 0, 'abc', 12345, (SELECT foo FROM bar), > /*more data follow*/); > > My problem is: > > The SELECT can either return data or NULL. > Everything is good when the data is returned, but the insert fails > when the NULL is returned, because the field "d" is a part of UNIQUE > INDEX. > > However,, I'd like to still insert the record and I'd like to do somethin= g > 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? > > Thank you.. > > > --0000000000003f24dc06458aeb5f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi
Did you try setting a default value to t= he field?

Atte
JRBM

El lun, 8 dic 2025 a las 21:40, Igor Korot (<ikorot01@gmail.com>) escribi=C3=B3:
Hi, ALL,
Consider the following scenario:

CREATE TABLE test(a INT, b VARCHAR(256), c INT, d VARCHAR(256), /*
more fields follows*/);
CREATE UNIQUE INDEX test_x( b, c, d );

Now I try to do:

INSERT INTO test VALUES( 0, 'abc', 12345, (SELECT foo FROM bar), /*more data follow*/);

My problem is:

The SELECT can either return data or NULL.
Everything is good when the data is returned, but the insert fails
when the NULL is returned, because the field "d" is a part of UNI= QUE
INDEX.

However,, I'd like to still insert the record and I'd like to do so= mething like:

INSERT INTO test VALUES( 0, 'abc', 12345, IF( (SELECT foo FROM bar)= =3D=3D
NULL, "postgres", <select_result>), /*more data follow*/);<= br>
What would be the best way to achieve this?

Thank you..


--0000000000003f24dc06458aeb5f--