sql-highlight icon indicating copy to clipboard operation
sql-highlight copied to clipboard

Any non-keyword word is considered as identifier

Open vladshcherbin opened this issue 1 year ago • 3 comments
trafficstars

Describe the bug

insert into "brands" ("name") values ('Aston Martin') returning "id", "name"

In this example returning keyword is not in keywords list and is considered as identifier.

Expected behavior Any non-keyword should be considered unknown or all keywords should be added to the keywords list.

All keywords can be taken from postgres docs

Screenshots

image

sql-highlight (please complete the following information):

  • Version: 5.0.0-beta.2

vladshcherbin avatar Mar 07 '24 15:03 vladshcherbin

This is also an issue for any non-postgres SQL dialect that has more/some other keywords.

Qtax avatar Mar 12 '24 13:03 Qtax

Any non-keyword should be considered unknown

If we did that though, then no strings would be marked as identifiers.

or all keywords should be added to the keywords list... All keywords can be taken from postgres docs

I guess that's a better argument, although I cringe to think that in a string like below, "a" and "c" would be marked as keywords rather than identifiers:

select * from tab where a > c

The current architecture (doing everything by regexp) has inherent limitations, so there need to be some compromises. It seems like adding all those strings as keywords might make things worse (overall) rather than better.

wkeese avatar Apr 06 '24 15:04 wkeese

PS: I guess what I'm saying is that it's only safe to list reserved keywords in the keywords section (and "returning" is non-reserved).

wkeese avatar Apr 06 '24 23:04 wkeese

Hey there. I think to avoid the odd cases such as a > c we'll just keep accepting suggestions for new keywords for the time being. The returning keyword was added in #188 so I'll mark this as closed.

scriptcoded avatar Jul 02 '24 20:07 scriptcoded