Re: update returning order by syntax error question - Mailing list pgsql-general

From Adrian Klaver
Subject Re: update returning order by syntax error question
Date
Msg-id 94b68d28-9cab-b640-3693-477f029991ff@aklaver.com
Whole thread Raw
In response to Re: update returning order by syntax error question  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: update returning order by syntax error question
List pgsql-general
On 9/12/19 6:44 AM, Tom Lane wrote:
> raf <raf@raf.org> writes:
>> It's almost as if the parser sees "update" as a possible
>> table name (rather than a reserved word) and "tblname"
>> as the alias for that table and it's expecting a comma
>> or left/right/full etc. when it seess the "t".
> 
> No, it's *exactly* as if that.  UPDATE is an unreserved
> keyword so it's fully legitimate as a table name.
> If you made the syntax be what the grammar is expecting:
> 
> regression=# select * from (update t cross join update t2);
> ERROR:  relation "update" does not exist
> LINE 1: select * from (update t cross join update t2);


I am not following.
PostgreSQL 11.5

The OP had:

with u as
   (update tblname t set ... where ... returning ...)
   select * from u order by ...;


I tested with:

WITH u AS (
     UPDATE up_test t SET col_2 = col_2 + 1 WHERE id < 3
     RETURNING *
)
SELECT * FROM u;
BEGIN
  id | col1 | col_2
----+------+-------
   1 | t    |     2
   2 | NULL |     3
(2 rows)

I'm missing something.

>                         ^
> 
>             regards, tom lane
> 
> 
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com



pgsql-general by date:

Previous
From: "Basques, Bob (CI-StPaul)"
Date:
Subject: Re: Web GUI for PG table ?
Next
From: Tom Lane
Date:
Subject: Re: update returning order by syntax error question