Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p0kxI-0006Ox-79 for pgsql-bugs@arkaria.postgresql.org; Thu, 01 Dec 2022 14:54:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p0kxF-0001cn-U9 for pgsql-bugs@arkaria.postgresql.org; Thu, 01 Dec 2022 14:54:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p0kIR-0001hD-UO for pgsql-bugs@lists.postgresql.org; Thu, 01 Dec 2022 14:12:16 +0000 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1p0kIO-0004gt-Si for pgsql-bugs@lists.postgresql.org; Thu, 01 Dec 2022 14:12:14 +0000 Received: by mail-wr1-x433.google.com with SMTP id q7so2880335wrr.8 for ; Thu, 01 Dec 2022 06:12:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deepbluecap-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:subject:from:content-language:to :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=esVe8dyAxsRPlpzRHlDbaazxrnDBaMQFLDlw/vckpyI=; b=uOfL43/8sEdo4rQoZ4her4UW7XcmSvQekjUnRKUwhgKO2P8O3UoEVyLBQwhgY/0Mf4 cKvYqr1UzLrGkKuRXznMNSPpmaB+JNA640WFRRKSEBHAigFdd22LYz7CScAieVBB3NAA Bdlu/Kpe1f7tt7RAydHY6YwZw8BkQpKCUUUscc2EF8HfycXOgdSBzOGNId6UpZGA9XUK dofiZALVDYMuCKYnjr3sYG+2NR9RL/1R/3dyLiHxNG1DOubIEcoTchF6gxTILDw3Qg9k V7NmB6/K2AZ2I42ZCHxHlPkD9wuCUlpzmkU8qeHhiO6XdlYWplm9cxrRPe4gKESOohCN wr+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:subject:from:content-language:to :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=esVe8dyAxsRPlpzRHlDbaazxrnDBaMQFLDlw/vckpyI=; b=w4rY96lIpKQro/rIHV7qu/S3kyCx93brjKv2S0RZr+TcNTZ2qyZhd7j/4Shf/juGCi o5SFHj74SSO4V5hFZ7QM5hzHd2lv/L/OAxo+nRfljUe8TwXQAkqTc/ZHQ7CdtmhyIPMX ozmAS9CBjnOKHSP2JYoHj57chClzaNMHsBWfPOIyKyrx4ULq3B0jZpJzYYtQVceZo0ym Z/2ShwEN+TfZSrdiYaioAyIv5uVDkXQ9ydQqG8DOxcou/NQP9/8pLTiqVqXeT+jYvRYu RRRedb6nLfOjUc2at4dVDvm5fZWA4keBl4GwAlDPWD2v6ZbU2c+H4uQZshj83GSsDIjh /edQ== X-Gm-Message-State: ANoB5plq4U5WehwX0tsLymW7nU8JFYd3ZaEjZ4M+eUDW+0xO7ebupFNT Fcdqu6qP1kikxKx6Q8JEGpwRSMMEBxudNYfzGBOx2Wecl8QUNL7qvZ1jWn23L56E8oXnzfMAQQq j462/SBOwSRjSDtSxhIrEEEbHmf85EqNlKX2tHyTriIIAW480CPxOUpGyL1qHiZyqrdJs0fAvX8 4HgLignuIEGeHJsQfk+cV2 X-Google-Smtp-Source: AA0mqf5ukebjWL+liu/BaVS+YS4eR1oLM/2MxXqae2ZdZwwDANa4g1K+ZCcRuLSAuTGJgSg/nq2fFQ== X-Received: by 2002:adf:e50f:0:b0:22c:cc75:5aab with SMTP id j15-20020adfe50f000000b0022ccc755aabmr39757870wrm.143.1669903930991; Thu, 01 Dec 2022 06:12:10 -0800 (PST) Received: from ?IPV6:2a01:e0a:255:1000:beb0:2d5c:4534:9c9e? ([2a01:e0a:255:1000:beb0:2d5c:4534:9c9e]) by smtp.gmail.com with ESMTPSA id j11-20020a05600c42cb00b003cf37c5ddc0sm5089030wme.22.2022.12.01.06.12.10 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 01 Dec 2022 06:12:10 -0800 (PST) Message-ID: Date: Thu, 1 Dec 2022 15:12:09 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 To: pgsql-bugs@lists.postgresql.org Content-Language: en-GB From: Duncan Sands Subject: pg_catalog.pg_get_viewdef pretty-print removes important parentheses Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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.