Re: SQL-standard function body
Julien Rouhaud <rjuju123@gmail.com>
From: Julien Rouhaud <rjuju123@gmail.com>
To: Jaime Casanova <jcasanov@systemguards.com.ec>
Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2021-03-15T08:14:48Z
Lists: pgsql-hackers
On Mon, Mar 15, 2021 at 04:03:44PM +0800, Julien Rouhaud wrote:
> On Mon, Mar 15, 2021 at 01:05:11AM -0500, Jaime Casanova wrote:
> > I found another problem when using CASE expressions:
> >
> > CREATE OR REPLACE FUNCTION foo_case()
> > RETURNS boolean
> > LANGUAGE SQL
> > BEGIN ATOMIC
> > select case when random() > 0.5 then true else false end;
> > END;
> >
> > apparently the END in the CASE expression is interpreted as the END of
> > the function
>
> I think that it's an issue in psql scanner. If you escape the semicolon or
> force a single query execution (say with psql -c), it works as expected.
Applying the following diff (not sending a patch to avoid breaking the cfbot)
the issue and doesn't seem to break anything else:
diff --git a/src/fe_utils/psqlscan.l b/src/fe_utils/psqlscan.l
index a492a32416..58026fe90a 100644
--- a/src/fe_utils/psqlscan.l
+++ b/src/fe_utils/psqlscan.l
@@ -871,7 +871,9 @@ other .
{identifier} {
cur_state->identifier_count++;
- if (pg_strcasecmp(yytext, "begin") == 0)
+ if ((pg_strcasecmp(yytext, "begin") == 0)
+ || (pg_strcasecmp(yytext, "case") == 0)
+ )
{
if (cur_state->identifier_count > 1)
cur_state->begin_depth++;
Commits
-
Don't crash on empty statements in SQL-standard function bodies.
- bfeede9fa464 14.0 landed
-
psql: Fix line continuation prompts for unbalanced parentheses
- d9a9f4b4b92a 14.0 landed
-
Provide query source text when parsing a SQL-standard function body.
- 409723365b27 14.0 landed
-
Revert "Cope with NULL query string in ExecInitParallelPlan()."
- 83efce7a1ebc 14.0 landed
-
Undo decision to allow pg_proc.prosrc to be NULL.
- 1111b2668d89 14.0 landed
-
SQL-standard function body
- e717a9a18b2e 14.0 landed
-
Move pg_stat_statements query jumbling to core.
- 5fd9dfa5f50e 14.0 cited
-
Extend SQL function tests lightly
- 11b80d900fe4 14.0 landed