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 1lqKrZ-0005u2-Qt for pgsql-hackers@arkaria.postgresql.org; Mon, 07 Jun 2021 19:24:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lqKrX-0002BR-Qy for pgsql-hackers@arkaria.postgresql.org; Mon, 07 Jun 2021 19:24:39 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lqKrX-0002BI-IC for pgsql-hackers@lists.postgresql.org; Mon, 07 Jun 2021 19:24:39 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lqKrV-0000rS-Dz for pgsql-hackers@lists.postgresql.org; Mon, 07 Jun 2021 19:24:38 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 157JOXHd982444; Mon, 7 Jun 2021 15:24:34 -0400 From: Tom Lane To: Peter Eisentraut cc: Julien Rouhaud , Noah Misch , Jaime Casanova , PostgreSQL Hackers Subject: Re: SQL-standard function body In-reply-to: <878524.1623079661@sss.pgh.pa.us> References: <20210315080344.wed62yy54fuse7jg@nol> <20210315081448.63vagqr3ly45l74i@nol> <20210331101256.d7h7d74o4celskt4@nol> <9277ef6a-bfa8-9c06-8e91-16c2892120cc@2ndquadrant.com> <20210403033943.dp6um65shvrovoj5@nol> <01c65ea6-e5bf-22f4-cacc-6d0f6853a965@2ndquadrant.com> <20210606044418.GA297923@rfd.leadboat.com> <20210606073220.42ytzr6r5bbhqh3q@nol> <993a2fe6-93b9-3364-21bb-6e2d8c0fde13@enterprisedb.com> <878524.1623079661@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Mon, 07 Jun 2021 11:27:41 -0400" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <982399.1623093824.0@sss.pgh.pa.us> Date: Mon, 07 Jun 2021 15:24:33 -0400 Message-ID: <982443.1623093873@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <982399.1623093824.1@sss.pgh.pa.us> I wrote: > ... I tend to agree with Julien's position here. It seems really ugly > to prohibit empty statements just for implementation convenience. > However, the way I'd handle it is to have the grammar remove them, > which is what it does in other contexts. Concretely, I think the right fix is per attached. Like Julien, I don't see any additional change in regression test outputs. Maybe Peter thinks there should be some? But I think the reverse-listing we get for functest_S_3a is fine. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="fix-empty-statements-2.patch"; charset="us-ascii" Content-ID: <982399.1623093824.2@sss.pgh.pa.us> Content-Description: fix-empty-statements-2.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 9ee90e3f13..52a254928f 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -7990,7 +7990,11 @@ opt_routine_body: routine_body_stmt_list: routine_body_stmt_list routine_body_stmt ';' { - $$ =3D lappend($1, $2); + /* As in stmtmulti, discard empty statements */ + if ($2 !=3D NULL) + $$ =3D lappend($1, $2); + else + $$ =3D $1; } | /*EMPTY*/ { diff --git a/src/test/regress/expected/create_function_3.out b/src/test/re= gress/expected/create_function_3.out index 5b6bc5eddb..5955859bb5 100644 --- a/src/test/regress/expected/create_function_3.out +++ b/src/test/regress/expected/create_function_3.out @@ -267,7 +267,7 @@ CREATE FUNCTION functest_S_3() RETURNS boolean RETURN false; CREATE FUNCTION functest_S_3a() RETURNS boolean BEGIN ATOMIC - RETURN false; + ;;RETURN false;; END; CREATE FUNCTION functest_S_10(a text, b date) RETURNS boolean LANGUAGE SQL diff --git a/src/test/regress/sql/create_function_3.sql b/src/test/regress= /sql/create_function_3.sql index 4b778999ed..6e8b838ff2 100644 --- a/src/test/regress/sql/create_function_3.sql +++ b/src/test/regress/sql/create_function_3.sql @@ -165,7 +165,7 @@ CREATE FUNCTION functest_S_3() RETURNS boolean RETURN false; CREATE FUNCTION functest_S_3a() RETURNS boolean BEGIN ATOMIC - RETURN false; + ;;RETURN false;; END; = CREATE FUNCTION functest_S_10(a text, b date) RETURNS boolean ------- =_aaaaaaaaaa0--