From: Duncan Sands <duncan.sands@deepbluecap.com>
To: pgsql-bugs@lists.postgresql.org
Subject: pg_catalog.pg_get_viewdef pretty-print removes important parentheses
Date: Thu, 1 Dec 2022 15:12:09 +0100
Message-ID: <f41566aa-a057-6628-4b7c-b48770ecb84a@deepbluecap.com> (raw)
When pg_catalog.pg_get_viewdef is called with pretty-print enabled, it removes
parentheses around (DATE + INTERVAL) in the construct "(DATE + INTERVAL) AT TIME
ZONE TZ", outputting SQL that fails to parse. Here is an example, showing that
the SQL output when pretty printing is off does parse, but does not parse when
pretty printing is on.
-- EXAMPLE BEGINS
$ psql
Pager usage is off.
SET
psql (15.1 (Ubuntu 15.1-1.pgdg22.04+1))
Type "help" for help.
duncan=> CREATE VIEW pg_temp.v AS SELECT ('2022-12-01'::date + INTERVAL '1 day')
AT TIME ZONE 'Europe/Paris';
CREATE VIEW
duncan=> SELECT pg_catalog.pg_get_viewdef('pg_temp.v'::regclass, false);
pg_get_viewdef
---------------------------------------------------------------------------------------------------
SELECT (('2022-12-01'::date + '1 day'::interval) AT TIME ZONE
'Europe/Paris'::text) AS timezone;
(1 row)
duncan=> SELECT (('2022-12-01'::date + '1 day'::interval) AT TIME ZONE
'Europe/Paris'::text) AS timezone;
timezone
------------------------
2022-12-02 00:00:00+01
(1 row)
duncan=> SELECT pg_catalog.pg_get_viewdef('pg_temp.v'::regclass, true);
pg_get_viewdef
-------------------------------------------------------------------------------------------------
SELECT ('2022-12-01'::date + '1 day'::interval AT TIME ZONE
'Europe/Paris'::text) AS timezone;
(1 row)
duncan=> SELECT ('2022-12-01'::date + '1 day'::interval AT TIME ZONE
'Europe/Paris'::text) AS timezone;
ERROR: function pg_catalog.timezone(text, interval) does not exist
LINE 1: SELECT ('2022-12-01'::date + '1 day'::interval AT TIME ZONE ...
^
HINT: No function matches the given name and argument types. You might need to
add explicit type casts.
-- EXAMPLE ENDS
This is annoying because psql's \ev pops up the pretty-printed version, and you
have to add the parentheses back in by hand in order to have the view definition
be accepted.
Best wishes, Duncan.
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 using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: duncan.sands@deepbluecap.com, pgsql-bugs@lists.postgresql.org
Subject: Re: pg_catalog.pg_get_viewdef pretty-print removes important parentheses
In-Reply-To: <f41566aa-a057-6628-4b7c-b48770ecb84a@deepbluecap.com>
* 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