From: | Erik Wienhold <ewie(at)ewie(dot)name> |
---|---|
To: | Michal Bartak <maxym(dot)srpl(at)gmail(dot)com> |
Cc: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
Subject: | Re: CASE control block broken by a single line comment |
Date: | 2024-04-06 21:14:23 |
Message-ID: | utvbxgxkzflf2tn73iejt3qn4devu3f3kbhqvwxm6qkeboe7wf@mg4gzyufd547 |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 2024-04-06 20:14 +0200, Michal Bartak wrote:
> The issue described bellow exists in postgresql ver 16.2 (found in some
> previous major versions)
Can confirm also on master.
> The documentation defines a comment as:
>
> > A comment is a sequence of characters beginning with double dashes and
> > extending to the end of the line
>
>
> When using such a comment within CASE control block, it ends up with an
> error:
>
> DO LANGUAGE plpgsql $$
> DECLARE
> t TEXT = 'a';
> BEGIN
> CASE t
> WHEN 'a' -- my comment
> THEN RAISE NOTICE 'a';
> WHEN 'b'
> THEN RAISE NOTICE 'b';
> ELSE NULL;
> END CASE;
> END;$$;
>
> ERROR: syntax error at end of input
> LINE 1: "__Case__Variable_2__" IN ('a' -- my comment)
> ^
> QUERY: "__Case__Variable_2__" IN ('a' -- my comment)
> CONTEXT: PL/pgSQL function inline_code_block line 5 at CASE
I'm surprised that the comment is not skipped by the scanner at this
point. Maybe because the parser just reads the raw expression between
WHEN and THEN with plpgsql_append_source_text via read_sql_construct.
How about the attached patch? It's a workaround by simply adding a line
feed character between the raw expression and the closing parenthesis.
--
Erik
Attachment | Content-Type | Size |
---|---|---|
v1-0001-plpgsql-create-valid-IN-expression-for-CASE-WHEN-.patch | text/plain | 2.6 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Corey Huinker | 2024-04-06 21:23:43 | Re: Statistics Import and Export |
Previous Message | Andres Freund | 2024-04-06 20:21:27 | Re: Flushing large data immediately in pqcomm |