Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Statement Splitter #135

Open
psteinroe opened this issue Aug 1, 2024 · 1 comment · May be fixed by #138
Open

Improve Statement Splitter #135

psteinroe opened this issue Aug 1, 2024 · 1 comment · May be fixed by #138
Assignees
Labels
enhancement New feature or request

Comments

@psteinroe
Copy link
Collaborator

The statement splitter is a crate that receives sql source and returns ranges for every statement in the file. It's supposed to work with incomplete and incorrect statements. Right now, the implementation is very simple and just looks at the first n tokens of a statement to check if a new one starts at the current cursor position.

This is very fragile, and should be improved. My current idea is to instead of just using the first n tokens, allow any tokens to be part of the declaration, so that e.g. the create function syntax

CREATE [ OR REPLACE ] [ CONSTRAINT ] TRIGGER name { BEFORE | AFTER | INSTEAD OF } { event [ OR ... ] }
    ON table_name
    [ FROM referenced_table_name ]
    [ NOT DEFERRABLE | [ DEFERRABLE ] [ INITIALLY IMMEDIATE | INITIALLY DEFERRED ] ]
    [ REFERENCING { { OLD | NEW } TABLE [ AS ] transition_relation_name } [ ... ] ]
    [ FOR [ EACH ] { ROW | STATEMENT } ]
    [ WHEN ( condition ) ]
    EXECUTE { FUNCTION | PROCEDURE } function_name ( arguments )

could be defined in the parser as

CREATE [ OR REPLACE ] [ CONSTRAINT ] TRIGGER <string> { BEFORE | AFTER | INSTEAD OF } <any-tokens> ON <string> <any-tokens> EXECUTE { FUNCTION | PROCEDURE } <string> ( arguments )

we would need the following definitions

  • a specific token
  • optional token
  • one of token
  • any string token
  • any number of tokens
@psteinroe psteinroe self-assigned this Aug 1, 2024
@psteinroe psteinroe added the enhancement New feature or request label Aug 1, 2024
@psteinroe psteinroe mentioned this issue Aug 1, 2024
14 tasks
@psteinroe psteinroe linked a pull request Aug 28, 2024 that will close this issue
4 tasks
@aleclarson
Copy link

I see you've already put a lot of work into this, but I'm curious why you don't split statements with libpg_query?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants