Skip to content

UDF: fix sql prompt to handle multiline statements inBEGIN ATOMIC...END clause  #84004

Open
@chengxiong-ruan

Description

@chengxiong-ruan

Is your feature request related to a problem? Please describe.
Currently sql prompt would finish a statement and send it to back when it sees ; character outside of a string and hit Enter. This make it hard to write CREATE FUNCTION with BEGIN ATOMIC...END clause because the sql statements within the function body are not contained in a string and they all end with ;. For example:

CREATE FUNCTION f() RETURNS INT LANGUAGE SQL
BEGIN ATOMIC
SELECT 1;
SELECT 2;
END;

Currently sql prompt would finish early when it sees the first ; after SELECT 1 and we'd see a syntax error.

Describe the solution you'd like
We need to make sql prompt aware that it enters the BEGIN ATOMIC context and continue the multiline statement even it sees ; outside of a string. We could track the tokens sql seen so far to recognize the context.

Jira issue: CRDB-17401

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-cli-clientCLI commands that pertain to using SQL featuresA-sql-routineUDFs and Stored ProceduresC-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)T-sql-foundationsSQL Foundations Team (formerly SQL Schema + SQL Sessions)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions