Thread: Except does not work as in the documentation

Except does not work as in the documentation

From
PG Doc comments form
Date:
The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/17/queries-union.html
Description:

The current documentation does not give the right syntax for using the
EXCEPT in a query.
This is the error when I ran the below:
select appt_id from wayfinder.patient_details where create_timestamp between
('2025-02-24 00:00:00' and '2025-02-25 00:00:00')
EXCEPT
select appt_id from wayfinder.appointment_details where create_timestamp
between ('2025-02-24 00:00:00' and '2025-02-25 00:00:00')
ERROR:  syntax error at or near "EXCEPT"
LINE 2: EXCEPT
        ^
SQL state: 42601
Character: 128

Re: Except does not work as in the documentation

From
Greg Sabino Mullane
Date:
Your BETWEEN statement has X AND Y inside of parenthesis. No parenthesis are needed, the format is:

BETWEEN X AND Y

not 

BETWEEN (X AND Y)

See:


Postgres is complaining about the EXCEPT because it is waiting for the next item in the BETWEEN clause. It just happened to be in the line of fire - any other word would have triggered an error as well.

Cheers,
Greg

--
Enterprise Postgres Software Products & Tech Support