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

SET TRANSACTION ... statement not supported #76

Open
jellelicht opened this issue May 10, 2022 · 3 comments · May be fixed by #81
Open

SET TRANSACTION ... statement not supported #76

jellelicht opened this issue May 10, 2022 · 3 comments · May be fixed by #81

Comments

@jellelicht
Copy link

begin; set transaction isolation level repeatable read, read only; commit; fail to parse.

With some pointers, I'd love to contribute a PR for this, if you're open to accepting it.

Docs:
https://www.postgresql.org/docs/current/sql-set-transaction.html

@oguimbal
Copy link
Owner

Sure, PRs are most welcome !

As a starting point, you can take a look to the A section in the contributing.md file of pg-mem repo (nb: implementing the parser part does not require implementing the statement in pg-mem, dont worry)

The hard part is understanding Nearley, but it is not very hard.

For some inspiration, you can have a look at #74 by @janpaepke which implements a simple statement (same level of complexity as SET TRANSACTION)

If you have questions, feel free to ask !

I'll add this feature anyway when I have some time if you dont, but I cant say when :)

@janpaepke
Copy link
Contributor

Did someone say ne..ne..nearley? 🤪

What would you expect the resulting AST to look like?

@oguimbal
Copy link
Owner

😄

My two cents: If implementing the whole documentation linked, there must be two statements.

The SET TRANSACTION SNAPSHOT one should be pretty straightfoward... something like this should do:

export interface SetTransactionSnapshot extends PGNode {
    type: 'set transaction snapshot';
    snapshotId: string;
}

As for the second one (which covers both SET TRANSACTION and SET SESSION CHARACTERISTICS AS TRANSACTION), something like that seems to cover all the cases and should not be too hard to fit to Nearley:

export interface SetTransactionMode extends PGNode {
    type: 'set transaction' | 'set session characteristics as transaction';
    mode: TransactionMode[];
}

export type TransactionMode = TransactionModeIsolationLevel  |  TransactionModeAccess | TransactionModeDeferability;

export interface TransactionModeIsolationLevel extends PGNode {
   type: 'isolation level';
   level: 'serializable' | 'repeatable read' | 'read committed' | 'read uncommitted';
}

export interface TransactionModeAccess extends PGNode {
   type: 'write mode';
   readWrite: boolean;
}

export interface TransactionModeDeferability extends PGNode {
   type: 'deferability';
   deferable: boolean;
}

nb: if you havent seen its usage elsewhere, to implement the 'serializable' | 'repeatable read' | 'read committed' | 'read uncommitted' part in Nearley, the toStr(matchedStatement).toLowerCase() utility should be quite useful to convert a big a | b | c nearley statement directly in the right string.

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

Successfully merging a pull request may close this issue.

3 participants