partiql-lang-kotlin icon indicating copy to clipboard operation
partiql-lang-kotlin copied to clipboard

Ability to modify SQL keyword list

Open mustafaakin opened this issue 2 years ago • 5 comments

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?

https://github.com/partiql/partiql-lang-kotlin/blob/e455cf44a972fd9f39cca171c3ef82946fe5b900/lang/src/org/partiql/lang/syntax/LexerConstants.kt#L30

Parser Error: at line 1, column 8: unexpected keyword found, KEYWORD : public

mustafaakin avatar Aug 24 '22 13:08 mustafaakin

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 avatar Aug 26 '22 20:08 johnedquinn

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.

johnedquinn avatar Aug 26 '22 20:08 johnedquinn

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'

mustafaakin avatar Aug 28 '22 07:08 mustafaakin

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.

johnedquinn avatar Sep 14 '22 20:09 johnedquinn

Hi @johnedquinn Is there any update on this?

cemkucuk avatar Apr 17 '23 14:04 cemkucuk