From: Tom Lane <tgl@sss.pgh.pa.us>
To: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Cc: Julien Rouhaud <rjuju123@gmail.com>
Cc: Noah Misch <noah@leadboat.com>
Cc: Jaime Casanova <jcasanov@systemguards.com.ec>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: SQL-standard function body
Date: Mon, 07 Jun 2021 15:24:33 -0400
Message-ID: <982443.1623093873@sss.pgh.pa.us> (raw)
In-Reply-To: <878524.1623079661@sss.pgh.pa.us>
References: <CAJKUy5j3N23=SuF=S=xX6mu8VX3N9qSbxiej2wMsAqZ3FB2Pow@mail.gmail.com>
<20210315080344.wed62yy54fuse7jg@nol>
<20210315081448.63vagqr3ly45l74i@nol>
<c17ea953-0837-70ab-b408-522421697d54@2ndquadrant.com>
<CAJKUy5giffMO31KfBxgSgcaXRC48HfhqwWB6fewAE_8cgOGe2w@mail.gmail.com>
<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>
<CAOBaU_ZMMwnkygU4OMc3gUtbt5FS0fbQBzQC=rJm6xYi4qEYKg@mail.gmail.com>
<878524.1623079661@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
Attachments:fix-empty-statements-2.patch (text/x-diff, 1.5K) downloaddiff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.yindex 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 ';'
{
- $$ = lappend($1, $2);+ /* As in stmtmulti, discard empty statements */+ if ($2 != NULL)+ $$ = lappend($1, $2);+ else+ $$ = $1;
}
| /*EMPTY*/
{
diff --git a/src/test/regress/expected/create_function_3.out b/src/test/regress/expected/create_function_3.outindex 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.sqlindex 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
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-hackers@postgresql.org
Cc: tgl@sss.pgh.pa.us, peter.eisentraut@enterprisedb.com, rjuju123@gmail.com, noah@leadboat.com, jcasanov@systemguards.com.ec, pgsql-hackers@lists.postgresql.org
Subject: Re: SQL-standard function body
In-Reply-To: <982443.1623093873@sss.pgh.pa.us>
* 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