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
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.
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
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
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.
Btw, the exact error message could be helpful and should be provided to see
misinterpretations.
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
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
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
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,
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 );
>>
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
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
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
14 matches
Mail list logo