pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Peter Eisentraut <peter@eisentraut.org>
To: pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: SQL-standard function body
Date: Fri, 09 Apr 2021 19:44:47 +0200
Message-ID: <cee01d26fe55bc086b3bcf10bfe4e8d450e2f608.camel@cybertec.at> (raw)
In-Reply-To: <E1lUEF5-00027L-N4@gemulon.postgresql.org>
References: <E1lUEF5-00027L-N4@gemulon.postgresql.org>

On Wed, 2021-04-07 at 19:53 +0000, Peter Eisentraut wrote:
> SQL-standard function body
> 
> This adds support for writing CREATE FUNCTION and CREATE PROCEDURE
> statements for language SQL with a function body that conforms to the
> SQL standard and is portable to other implementations.
> 
> [...]
>
> psql needs some new intelligence to keep track of function body
> boundaries so that it doesn't send off statements when it sees
> semicolons that are inside a function body.

This causes psql to fail to recognize the semicolon in the following
statement as the end of a statement:

  IMPORT FOREIGN SCHEMA x FROM SERVER y INTO z OPTIONS (case 'lower');

The cause is the "case", which is recognized as the start of a function
body.

Now you could argue that "case" is a reserved word, and I should
double quote it if I insist on using it as a FDW option, but it
is a regression.

Would it be an option to recognize BEGIN and CASE as starting a
function body only if they are *not* inside parentheses, like in
the attached?

Yours,
Laurenz Albe

Attachments:

0001-Improve-psql-s-parsing-of-SQL-standard-function-bodi.patch (text/x-patch, 1.1K) download From 8c95440905c01b8c9ed8b46ef01a24b01f24580d Mon Sep 17 00:00:00 2001 From: Laurenz Albe <laurenz.albe@cybertec.at> Date: Fri, 9 Apr 2021 19:40:36 +0200 Subject: [PATCH] Improve psql's parsing of SQL standard function bodies Treat BEGIN and CASE as the start of a function body only if we are not inside parentheses. That allows statements like the following to be parsed correctly: ALTER FOREIGN TABLE x OPTIONS (ADD case 'upper'); --- src/fe_utils/psqlscan.l | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/fe_utils/psqlscan.l b/src/fe_utils/psqlscan.l index 4ec57e96a9..dbfcfc84e5 100644 --- a/src/fe_utils/psqlscan.l +++ b/src/fe_utils/psqlscan.l @@ -871,8 +871,9 @@ other . {identifier} { cur_state->identifier_count++; - if (pg_strcasecmp(yytext, "begin") == 0 - || pg_strcasecmp(yytext, "case") == 0) + if (cur_state->paren_depth == 0 + && (pg_strcasecmp(yytext, "begin") == 0 + || pg_strcasecmp(yytext, "case") == 0)) { if (cur_state->identifier_count > 1) cur_state->begin_depth++; -- 2.26.3

view thread (18+ messages)  latest in thread

Message-ID: <cee01d26fe55bc086b3bcf10bfe4e8d450e2f608.camel@cybertec.at>
Permalink:  ../cee01d26fe55bc086b3bcf10bfe4e8d450e2f608.camel@cybertec.at/
Also on:    postgresql.org/message-id/cee01d26fe55bc086b3bcf10bfe4e8d450e2f608.camel@cybertec.at

 ·  · 

reply

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-committers@postgresql.org
  Cc: laurenz.albe@cybertec.at, peter@eisentraut.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: SQL-standard function body
  In-Reply-To: <cee01d26fe55bc086b3bcf10bfe4e8d450e2f608.camel@cybertec.at>

* 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