From: raf <raf@raf.org>
To: pgsql-general@postgresql.org
Subject: update returning order by syntax error question
Date: Thu, 12 Sep 2019 13:17:43 +1000
Message-ID: <20190912031743.jfbfj7e5ri5is36t@raf.org> (raw)
Hi,
postgresql-9.6.15
I just tried something like:
select * from
(update tblname t set ... where ... returning ...)
order by ...;
assuming it would work but it didn't.
That's OK. I found on stackoverflow
that a CTE can be used to do it:
with u as
(update tblname t set ... where ... returning ...)
select * from u order by ...;
What surprises me is the syntax error:
ERROR: syntax error at or near "t"
LINE 2: tblname t
^
If the syntax was invalid because an update returning
statement can't appear in a from clause, I'd expect the
error to be at the token "update".
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".
Anyone care to explain why the error is what it is?
It's no big deal. I'm just curious.
cheers,
raf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: raf@raf.org
Subject: Re: update returning order by syntax error question
In-Reply-To: <20190912031743.jfbfj7e5ri5is36t@raf.org>
References: <20190912031743.jfbfj7e5ri5is36t@raf.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox