Puzzled by ROW constructor behaviour?

From: Eagna <eagna(at)protonmail(dot)com>
To: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Puzzled by ROW constructor behaviour?
Date: 2022-11-22 21:11:00
Message-ID: K1pl2RffHja6dj8lhYxL8J2FcbfaHau4O41XeWAsLLDWeQace2-l6GPIk49Ha4vh0FSewhOyUveTu96Rv2gvQDf77wElA0Vad0FSo7w_U6A=@protonmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


Hi all,

I'm puzzled by some behaviour of the ROW constructor that I noticed when I was playing around.

From the documentation (https://www.postgresql.org/docs/current/sql-expressions.html#SQL-SYNTAX-ROW-CONSTRUCTORS), we have

NUMBER 1

> SELECT ROW(1,2.5,'this is a test') = ROW(1, 3, 'not the same') AS test1;

result:

> test1
> f

This is fine.

and then

NUMBER 2

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

result:

> test2
> t

OK - notice the equivalence of a ROW constructor and a VALUES clause.

So, then I create this table:

> CREATE TABLE test
> (
> a INT NOT NULL,
> b INT NOT NULL,
> c TEXT NOT NULL
> );

and then tried:

NUMBER 3

> INSERT INTO test ((ROW (1, 2.4, 'test...')));

and I get:

> ERROR: syntax error at or near "ROW"
> LINE 1: INSERT INTO test ((ROW (1, 2.4, 'test...')));

I tried various permutations of brackets and whatnot but nothing doing.

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

TIA and rgs,

E.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Steve Baldwin 2022-11-22 21:19:29 Re: Puzzled by ROW constructor behaviour?
Previous Message Brad White 2022-11-22 20:53:01 Re: Upgrading to v12