Re: except all & WITH - syntax error? - Mailing list pgsql-general

From Tom Lane
Subject Re: except all & WITH - syntax error?
Date
Msg-id 63780.1530544433@sss.pgh.pa.us
Whole thread Raw
In response to except all & WITH - syntax error?  (pinker <pinker@onet.eu>)
Responses Re: except all & WITH - syntax error?  (pinker <pinker@onet.eu>)
List pgsql-general
pinker <pinker@onet.eu> writes:
> Something strange happened to me right now. I'm trying to compare results
> from one query with rewritten version and everything is ok with this order:

> WITH abc AS (SELECT 1) SELECT 1
> except all
> SELECT 1

> but when I'm trying other way around it throws an error:
> SELECT 1
> except all
> WITH abc AS (SELECT 1) SELECT 1

You need some parens:

# SELECT 1
except all
(WITH abc AS (SELECT 1) SELECT 1);
 ?column? 
----------
(0 rows)

In your first example, the WITH actually attaches to the whole EXCEPT
construct, not the first sub-select as I suspect you're thinking.

In short: WITH has lower syntactic precedence than UNION/INTERSECT/EXCEPT.
You need parens if you want it to work the other way 'round.

            regards, tom lane


pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Not able to update some rows in a table
Next
From: Adrian Klaver
Date:
Subject: Re: Not able to update some rows in a table