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

Ability to modify SQL keyword list #719

Open
mustafaakin opened this issue Aug 24, 2022 · 5 comments
Open

Ability to modify SQL keyword list #719

mustafaakin opened this issue Aug 24, 2022 · 5 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@mustafaakin
Copy link

mustafaakin commented Aug 24, 2022

I know keywords come from the spec, however the popular words like domain, user, public is not actually useful in this library, not used in any way but we need to escape them as SELECT * FROM "user" which does not look nice. Would you consider the ability to customize that list as an advanced, somewhat hidden feature?

@JvmField internal val SQL92_KEYWORDS = setOf(

Parser Error: at line 1, column 8: unexpected keyword found, KEYWORD : public
@johnedquinn
Copy link
Member

Hi @mustafaakin, we discussed this as a team, and it's a feature request that we are certainly interested in pursuing in the future. I can't say exactly when we'd implement this, but we actually have discussed to a certain degree how we can implement this with the upcoming PartiQLParser, a new implementation of Parser -- see #711. Linking the PR because it would subtantially decrease the time to roll this feature out.

SQL has reserved and non-reserved keywords, and I believe domain, user, and public are all non-reserved. With the new PartiQLParser, in #711, it is quite easy to add a rule in PartiQL.g4, perhaps called nonReservedKeyword which would return a PartiqlAst identifier.

@johnedquinn johnedquinn added enhancement New feature or request good first issue Good for newcomers labels Aug 26, 2022
@johnedquinn
Copy link
Member

Update: PostgreSQL has a list of reserved vs non-reserved keywords on their website.

According to their implementation, user and public are reserved. We'd need to do research to see if it's at all possible to add user and public to PartiQL's future non-reserved keyword list.

@mustafaakin
Copy link
Author

For now, we've forked LexerConstants.kt in the runtime, which works for us. For Postgres, I've tried the following, only user needs to be quoted, though, but it parses the query, but user resolves to the actual SQL user.

CREATE TABLE tmp3 (
    "user" TEXT,
    public BOOLEAN,
    domain TEXT
);

INSERT INTO tmp3 VALUES('mustafa', true, 'resmo.com');

SELECT * FROM tmp3 WHERE user = 'mustafa'; <-- does not match because SQL user is resmo
SELECT * FROM tmp3 WHERE "user" = 'mustafa'; 
SELECT * FROM tmp3 WHERE public AND domain = 'resmo.com'

@johnedquinn
Copy link
Member

BTW @mustafaakin -- I created the above PR to add this to the new default parser (PartiQLParser). Should be extremely easy to modify the list of non-reserved keywords once it's merged.

@cemkucuk
Copy link

Hi @johnedquinn Is there any update on this?

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

Successfully merging a pull request may close this issue.

3 participants