Re: How do I check for NULL

2025-12-09 Thread Justin Swanhart
The key is the scalar subquery. A scalar subquery which selects no rows returns NULL. https://sqlfiddle.com/postgresql/online-compiler?id=e439059a-d46d-4d49-b8ab-9ff533656066 On Tue, Dec 9, 2025, 5:33 PM Thiemo Kellner wrote: > > On 12/9/25 18:29, David G. Johnston wrote: > > On Tue, Dec 9, 20

Re: How do I check for NULL

2025-12-09 Thread Thiemo Kellner
On 12/9/25 18:29, David G. Johnston wrote: On Tue, Dec 9, 2025 at 10:14 AM Thiemo Kellner wrote: I feel, you meant to say, the subquery does not return any record which is not the same as returns NULL. For a scalar subquery the final output of a zero-row query is the null value.

Re: How do I check for NULL

2025-12-09 Thread David G. Johnston
On Tue, Dec 9, 2025 at 1:40 PM Juan Rodrigo Alejandro Burgos Mella < [email protected]> wrote: > > Did you try setting a default value to the field? > >> >> Defaults don't work if you actually intend to conditionally override them -- or at least it requires something beyond a simple sel

Re: How do I check for NULL

2025-12-09 Thread Juan Rodrigo Alejandro Burgos Mella
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ó: > 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

Re: How do I check for NULL

2025-12-09 Thread David G. Johnston
On Tue, Dec 9, 2025 at 10:14 AM Thiemo Kellner wrote: > I feel, you meant to say, the subquery does not return any record which is > not the same as returns NULL. > For a scalar subquery the final output of a zero-row query is the null value. David J.

How do I check for NULL

2025-12-09 Thread Thiemo Kellner
Btw, the exact error message could be helpful and should be provided to see misinterpretations.

How do I check for NULL

2025-12-09 Thread Thiemo Kellner
Hi I believe there is a misconception. I feel, you meant to say, the subquery does not return any record which is not the same as returns NULL. In any case, I suggest you to use the "insert select" construct, see examples in https://www.postgresql.org/docs/current/sql-insert.html, e.g. "NSERT I

Re: How do I check for NULL

2025-12-09 Thread Adrian Klaver
On 12/8/25 23:53, Igor Korot wrote: Hi, Davd, On Mon, Dec 8, 2025 at 6:44 PM 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

Re: How do I check for NULL

2025-12-09 Thread David G. Johnston
Tuesday, December 9, 2025, Igor Korot wrote: > Hi, Davd, > > On Mon, Dec 8, 2025 at 6:44 PM 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 t

Re: How do I check for NULL

2025-12-08 Thread Igor Korot
Hi, Davd, On Mon, Dec 8, 2025 at 6:44 PM 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) == >> NULL,

Re: How do I check for NULL

2025-12-08 Thread Ron Johnson
On Mon, Dec 8, 2025 at 9:51 PM Ron Johnson wrote: > On Mon, Dec 8, 2025 at 9:40 PM Igor Korot wrote: > >> 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 ); >>

Re: How do I check for NULL

2025-12-08 Thread Ron Johnson
On Mon, Dec 8, 2025 at 9:40 PM Igor Korot wrote: > 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', 1234

Re: How do I check for NULL

2025-12-08 Thread David G. Johnston
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) == > NULL, "postgres", ), /*more data follow*/); > > What would be the best way to achieve

How do I check for NULL

2025-12-08 Thread Igor Korot
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: Th