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 1vSne5-005x5U-0Z for pgsql-general@arkaria.postgresql.org; Tue, 09 Dec 2025 02:40:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vSne2-002LAF-2t for pgsql-general@arkaria.postgresql.org; Tue, 09 Dec 2025 02:40:07 +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 1vSne2-002LA6-1W for pgsql-general@lists.postgresql.org; Tue, 09 Dec 2025 02:40:06 +0000 Received: from mail-yw1-x1130.google.com ([2607:f8b0:4864:20::1130]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vSne0-003xb1-0m for pgsql-general@lists.postgresql.org; Tue, 09 Dec 2025 02:40:06 +0000 Received: by mail-yw1-x1130.google.com with SMTP id 00721157ae682-787eb2d8663so72523247b3.0 for ; Mon, 08 Dec 2025 18:40:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765248001; x=1765852801; darn=lists.postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=boHADEW5VV6zBENz6sN2UuFn3arNhaIj/9qBrxff/Lk=; b=Q9rqiAagt0C8/2prg/zaOvAKZIvzg/FDGaPy9aK/IFC7obWAcbWclJd+JazinJAxU8 D02fDp+8+NQyHSgi0sPFmGyV9iHnuSCbDKqUYcVvAVdykU6xvEPVvwJ2s4kIjGGR1Zg4 lqc9niF1bgJsQ+9ahsYJqOiw8QHQxBGJDJWLyrnNNROzo99LvmYGVCnFOInfeV8Qu2F+ xksMDh0mzymyPL2/qnRYhCpc2tqeNFiz2rMDFsa+T2jS0VodkAbgBgcptv4JfgKh1oX5 hRNqeYKTvmKqsWZ7js/R0KEX9NiM6SU3LM5TAxE4ITFLznJvLOy7CSEWiQxAvDwaIzn0 8jGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765248001; x=1765852801; h=to:subject:message-id:date:from:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=boHADEW5VV6zBENz6sN2UuFn3arNhaIj/9qBrxff/Lk=; b=wzqetCCX1hAC4zGxWlVjnj7RpnajMSXwlX/8ni8opJgOJh51C5NFoH2Z1Wic2Tl/zL iSiwjIfocjmoEvbrfd55NKR666BcKjqOeKKnDD4Sn5KbRBAzooYutXzTotzEjOUOPJ5k mfUhJNi4mweJ9jM0qsZF72z+68Y3ViHNRI7XfTTI/QcPVP6dHXjwdnrOw3vbLBfce8TX n529hH36L/bnm1skCI0U7zSYgVWV+vUUlUpbAmL3oi1zim+2UGhar9XalsZpiy+dflEF CAUYA3ne8Mdz3Bp21a/K5pXc+/qw7V0rIz/6bWg9rAgexkAj9/DOSpa+MSFS4OXq9BJt Zz2g== X-Gm-Message-State: AOJu0YyDfRUwoJ9b9SZ33GFehuFBLFploCERfMsx6beLC0jPFSqBWhmr 4ZYTwZYLYsuaAEa1JN2lagSH/rF/LDY3AmVaXEd545Z2yuMHsPxJ8OJr0Gc2e3OrzquGU0nk76k 3q/F19W58L7ybHXknOyPIPsFHXt4RITwkU/TIJQY= X-Gm-Gg: AY/fxX5H0qYA7Fgd5tP1TkIFFnkZNw1fl9CjF3b8dIKcJiyn97RZMYEIZtwiGv1XT8u K+xslnWsmXyLQ8hZbNo80QjUsu71YVzXpFc828xONEPkoh4nIWjElLMQbcMVDWv4zGvi3Qz/KB4 DudqDMs7BD9G88f8n0xUQphgnnajj7BX4zYWuWEo59fG59ZHqf1xsOfxtGUp3DoWRCSKXSbR71T 5lFyv8XpfPclIF2FSXMjGvdVYaxInalsKucWnEZ746aNZCbd4pzwIx/FlACShE1ovqpiwjSLAD3 CMVxg7+SGGaYy0a11wBjorI9BaI= X-Google-Smtp-Source: AGHT+IHYkp+jok4Q1y4RuLLIVU+qlKYOBp6rsmQRmWgFD78vg5ixNw4jwsZvzcjabY1qdOTiTC6yPKBsd7PLkdV9gtk= X-Received: by 2002:a05:690e:d5a:b0:644:60d9:8660 with SMTP id 956f58d0204a3-64467a68bd6mr19543d50.44.1765248001274; Mon, 08 Dec 2025 18:40:01 -0800 (PST) MIME-Version: 1.0 From: Igor Korot Date: Mon, 8 Dec 2025 18:39:46 -0800 X-Gm-Features: AQt7F2oPgNkA_PkS1gcC-41_iwrJGY8s9xT3XKotp0NBQ7CfOT1NVOuWEfSoxEQ Message-ID: Subject: How do I check for NULL To: "pgsql-generallists.postgresql.org" Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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 something like: INSERT INTO test VALUES( 0, 'abc', 12345, IF( (SELECT foo FROM bar) == NULL, "postgres", ), /*more data follow*/); What would be the best way to achieve this? Thank you..