public inbox for [email protected]  
help / color / mirror / Atom feed
From: Juan Rodrigo Alejandro Burgos Mella <[email protected]>
To: Igor Korot <[email protected]>
Cc: pgsql-generallists.postgresql.org <[email protected]>
Subject: Re: How do I check for NULL
Date: Tue, 9 Dec 2025 15:40:04 -0500
Message-ID: <CAHbZ42z=Xp3VYARgipRcp0cBBQP+rNNUgoAp2dPzKbgDqPapxQ@mail.gmail.com> (raw)
In-Reply-To: <CA+FnnTw=18Rba2XgceRUFKQo5P7Xf9QhXT6wKF=DgzYT6K9-sw@mail.gmail.com>
References: <CA+FnnTw=18Rba2XgceRUFKQo5P7Xf9QhXT6wKF=DgzYT6K9-sw@mail.gmail.com>

Hi
Did you try setting a default value to the field?

Atte
JRBM

El lun, 8 dic 2025 a las 21:40, Igor Korot (<[email protected]>) escribió:

> 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", <select_result>), /*more data follow*/);
>
> What would be the best way to achieve this?
>
> Thank you..
>
>
>


view thread (14+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: How do I check for NULL
  In-Reply-To: <CAHbZ42z=Xp3VYARgipRcp0cBBQP+rNNUgoAp2dPzKbgDqPapxQ@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox