Re: Puzzled by ROW constructor behaviour? - Mailing list pgsql-general

From David G. Johnston
Subject Re: Puzzled by ROW constructor behaviour?
Date
Msg-id CAKFQuwbcZyooFZ_MmHTEtDepwxovT6pcpfy8iZ1Ag4DBCc+BmA@mail.gmail.com
Whole thread Raw
In response to Puzzled by ROW constructor behaviour?  (Eagna <eagna@protonmail.com>)
List pgsql-general
On Tue, Nov 22, 2022 at 2:11 PM Eagna <eagna@protonmail.com> wrote:

NUMBER 2

> SELECT ROW(1, 2.5, 'this is a test') = (VALUES (1, 2.5, 'this is a test')) AS test2;

My question is that if a ROW constructor works for a VALUES clause in statement NUMBER 2, then why not NUMBER 3?

You've drawn a false equivalence from the similarity of the syntax.

The following also works:

SELECT 1 = (SELECT 1*1);
But I don't think there is any argument that while this works:

INSERT INTO tbl (col) SELECT 1*1;

This doesn't:

INSERT INTO tbl (col) 1;

There is no difference with replacing 1 with a composite type and the SELECT subquery with VALUES instead.

Your "VALUES" is just a scalar subquery expression that, if it indeed produces a single row and column, can be compared to any other scalar value (if it produces more than one row you will get an error - try it).

David J.

pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Upgrading to v12
Next
From: Thomas Munro
Date:
Subject: Re: Getting PSQL in Windows to support TAB/Autocomplete via modified readline...