Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 16, 2025

The KEY keyword was reserved in all contexts, preventing its use as column or table names. This caused parse errors for common schemas where "key" is a natural identifier (e.g., key-value stores, API keys).

Changes

Grammar modifications (src/alasqlparser.jison):

  • Added KEY as explicit Literal alternative to allow use as identifier
  • Removed standalone KEY Literal variant from IndexKey rule (eliminates parser ambiguity when parsing column definitions)
  • Fixed IndexKey to use ColsList for consistency with PrimaryKey/ForeignKey

Test coverage (test/test2203.js):

  • 13 test cases validating KEY works as column/table name in SELECT, WHERE, JOIN, GROUP BY, ORDER BY
  • Verifies PRIMARY KEY, FOREIGN KEY, UNIQUE KEY syntax unchanged

Example

-- Now works without escaping
CREATE TABLE cache (id INT, key VARCHAR(50), data TEXT);
SELECT * FROM cache WHERE key = 'user:123';

-- Standard SQL KEY constructs still work
CREATE TABLE users (id INT PRIMARY KEY, email VARCHAR(100));
CREATE TABLE items (id INT, FOREIGN KEY (user_id) REFERENCES users(id));

Breaking Change

Index creation via KEY idx_name (column) no longer supported. Use INDEX idx_name (column) instead. This MySQL-specific variant was redundant with the standard INDEX keyword.

Original prompt

This section details on the original issue you should resolve

<issue_title>Limit the impact of using the keyword: KEY</issue_title>
<issue_description>
Just like in #2203 we want to limit the impact of having keywords. Preferably by making them keywords only in the context needed so the string/word can be used for things like table names and column names i the data - if possible. It might be too much of a hassle to make the impact less, but lets investigate what is possible - still sticking to the SQL-99 specs.

Start by making a test file named test0000.js where 0000 is the issue ID of this ticket. Replicate the use and mimic what usecases could make sense to test, like as a table name, as a column name, as a graph search. Things lke that.

The grammar can be updated in alasqlgrammar.jison. Focus on small precise changes. After updating it we need to run yarn jison && yarn test

Always run yarn format before committing.

</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Limit the impact of using the keyword: KEY Make KEY keyword usable as identifier in column and table names Dec 16, 2025
Copilot AI requested a review from mathiasrw December 16, 2025 23:04
Copilot AI and others added 6 commits December 18, 2025 00:01
Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
@mathiasrw mathiasrw force-pushed the copilot/limit-keyword-impact branch from e57ffda to bf532b1 Compare December 17, 2025 13:02
@mathiasrw mathiasrw marked this pull request as ready for review December 17, 2025 13:40
@mathiasrw mathiasrw merged commit a671e74 into develop Dec 17, 2025
10 checks passed
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 this pull request may close these issues.

Limit the impact of using the keyword: KEY

2 participants