Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 19, 2025

Description

Adds support for JSON column names containing the @ symbol using backticks or qualified column syntax. This allows querying JSON documents with @ in column names (at the beginning, middle, or end) while maintaining backward compatibility with SQL Server variable syntax.

Changes Made

  • Grammar Update: Modified alasqlparser.jison to add Literal DOT AT Literal rule in the Column production, enabling qualified column references like t.@version
  • Test File: Created test884.js with comprehensive tests for @ symbol handling in column names
  • Parser Regeneration: Regenerated alasqlparser.js using jison

Usage

For JSON columns with @ symbol, use one of these approaches:

  1. Backticks (supports @ anywhere in name): SELECT `@version`, `col@middle`, `end@` FROM ?
  2. Qualified syntax (for @ at start with table alias): SELECT t.@version FROM ? AS t

The unqualified syntax without backticks (SELECT @version FROM ?) is not supported to avoid conflicts with SQL Server variable syntax (@variable).

Testing

  • ✅ test884.js: All 4 tests pass
    • Backtick syntax for @ columns (beginning of name)
    • Qualified column syntax (table.@column)
    • Multiple @ columns
    • @ in middle or end of column names with backticks
  • ✅ test374.js: SQL Server variable tests still pass (no regression)
  • ✅ All existing tests pass (except unrelated timeout in test2112)
  • ✅ Graph select notation preserved and unaffected

Notes

This implementation balances support for JSON column names with @ while preserving existing SQL Server variable functionality (DECLARE @var, SET @var, SELECT @var). Backticks (`) provide the most flexible approach, supporting @ at any position in the column name.

Fixes #884

Original prompt

This section details on the original issue you should resolve

<issue_title>@ symbol in column name.</issue_title>
<issue_description>I have a column name within my json document that is prefixed with an @ sign.

How would I construct a query to be able to select this out.

var json = [{
_id: "someID",
@version: "1"
},
{_id: "someID2",
@version: "1"
}];

var sql = "SELECT _id,@version FROM ? ";
var x = alasql(sql, [json]);

At the moment I get a Uncaught TypeError

Uncaught TypeError: e.selectfn is not a function
    at d (http://cdn.jsdelivr.net/alasql/0.3/alasql.min.js:2:11437)
    at d (http://cdn.jsdelivr.net/alasql/0.3/alasql.min.js:2:12239)
    at c (http://cdn.jsdelivr.net/alasql/0.3/alasql.min.js:2:7501)
    at u (http://cdn.jsdelivr.net/alasql/0.3/alasql.min.js:2:7422)
    at Object.A.options.autocommit.A.databases.(anonymous function).engineid.A.databases.(anonymous function).tables.(anonymous function).view.A.databases.(anonymous function).tables.(anonymous function).view.a.datafn (http://cdn.jsdelivr.net/alasql/0.3/alasql.min.js:12:11100)
    at http://cdn.jsdelivr.net/alasql/0.3/alasql.min.js:2:6976
    at Array.forEach (native)
    at o (http://cdn.jsdelivr.net/alasql/0.3/alasql.min.js:2:6936)
    at s (http://cdn.jsdelivr.net/alasql/0.3/alasql.min.js:12:8352)
    at Function.A.dexec (http://cdn.jsdelivr.net/alasql/0.3/alasql.min.js:11:16165)
    at Function.A.exec (http://cdn.jsdelivr.net/alasql/0.3/alasql.min.js:11:15929)
    at A (http://cdn.jsdelivr.net/alasql/0.3/alasql.min.js:2:20273)
    at eval (eval at bindGrid (http://localhost:28706/BigData:8:33), <anonymous>:1:1)
    at bindGrid (http://localhost:28706/BigData:256:33)
    at addColumn (http://localhost:28706/BigData:293:33)
    at Object.checkChanged (http://localhost:28706/BigData:344:37)
    at Object._trigger (http://localhost:28706/Scripts/ej/web/ej.web.all.min.js:10:12821)
    at Object._onClickCheckList (http://localhost:28706/Scripts/ej/web/ej.web.all.min.js:10:1222656)
    at Object.proxy (http://localhost:28706/Scripts/jquery-3.1.1.js:502:14)
    at Object._trigger (http://localhost:28706/Scripts/ej/web/ej.web.all.min.js:10:12821)
    at Object._checkedHandler (http://localhost:28706/Scripts/ej/web/ej.web.all.min.js:10:648533)
    at HTMLSpanElement.<anonymous> (http://localhost:28706/Scripts/ej/web/ej.web.all.min.js:10:26546)
    at HTMLSpanElement.dispatch (http://localhost:28706/Scripts/jquery-3.1.1.js:5201:27)
    at HTMLSpanElement.elemData.handle (http://localhost:28706/Scripts/jquery-3.1.1.js:5009:28)
d @ alasql.min.js:2
d @ alasql.min.js:2
c @ alasql.min.js:2
u @ alasql.min.js:2
A.options.autocommit.A.databases.(anonymous function).engineid.A.databases.(anonymous function).tables.(anonymous function).view.A.databases.(anonymous function).tables.(anonymous function).view.a.datafn @ alasql.min.js:12
(anonymous) @ alasql.min.js:2
o @ alasql.min.js:2
s @ alasql.min.js:12
A.dexec @ alasql.min.js:11
A.exec @ alasql.min.js:11
A @ alasql.min.js:2
(anonymous) @ VM5622:1
bindGrid @ BigData:256
addColumn @ BigData:293
checkChanged @ BigData:344
_trigger @ ej.web.all.min.js:10
_onClickCheckList @ ej.web.all.min.js:10
proxy @ jquery-3.1.1.js:502
_trigger @ ej.web.all.min.js:10
_checkedHandler @ ej.web.all.min.js:10
(anonymous) @ ej.web.all.min.js:10
dispatch @ jquery-3.1.1.js:5201
elemData.handle @ jquery-3.1.1.js:5009

</issue_description>

<agent_instructions>Please make a test file called test884.js verifying if this issue is still a problem.

If it is a problem try to solve it.

If you need to update the grammar of alasql, then please do small precice changes to alasqlparser.jison and then run yarn jison && yarn test</agent_instructions>

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

@mathiasrw Please try to wrap the column name in ``` ` ``` and let me know if it worked
SELECT `_id`, `@Version` FROM ?
```</body></comment_new>
</comments>


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

{ $$ = new yy.Column({columnid: $3, tableid: $1});}
| Literal DOT VALUE
{ $$ = new yy.Column({columnid: $3, tableid: $1});}
| Literal DOT AT Literal
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this is the original intent? Is the point not to have @ in any part of the name?

also: how does it affect the current graph select notation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change on line 1184 adds support for qualified column references with @ (e.g., table.@column). This allows accessing JSON columns with @ when using table aliases. For unqualified references, backticks are still required (e.g., `@version`) to avoid conflicts with SQL Server variable syntax (@variable).

Regarding graph select notation: The AT Literal syntax used in graph selectors (lines 651-658) is preserved and unaffected. This change only adds a new alternative in the Column rule for qualified column names.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if the @ is in the middle of the name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backticks handle @ anywhere in the column name (beginning, middle, or end). Added test in commit 9c44576 demonstrating this:

  • `col@middle` ✅ works
  • `end@` ✅ works
  • `@start@end` ✅ works

The BRALITERAL token (backticks) accepts any characters, so no grammar changes are needed for this case.

@mathiasrw
Copy link
Member

mathiasrw commented Nov 19, 2025

@copilot please run yarn jison $$ yarn test && yarn format

@blacksmith-sh

This comment has been minimized.

Copy link
Contributor Author

Copilot AI commented Nov 19, 2025

@copilot please run yarn jison $$ yarn test && yarn format

Completed in commit d6ddc0d:

  • yarn jison - Parser regenerated successfully
  • yarn test - All tests pass (except unrelated timeout in test2112)
  • yarn format - Code formatted (test884.js unchanged, already formatted)

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • upload.wikimedia.org
    • Triggering command: /usr/local/bin/node node_modules/mocha/bin/mocha.js ./test --reporter dot --bail (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@mathiasrw mathiasrw marked this pull request as ready for review November 19, 2025 13:10
Copilot AI changed the title [WIP] Fix query selection for json column with @ symbol Support @ symbol in qualified column names (table.@column) Nov 19, 2025
Copilot AI requested a review from mathiasrw November 19, 2025 13:12
Copilot finished work on behalf of mathiasrw November 19, 2025 13:12
@mathiasrw
Copy link
Member

@copilot what if the @ is in the middle of the name?

Copy link
Contributor Author

Copilot AI commented Nov 19, 2025

@copilot what if the @ is in the middle of the name?

Backticks handle @ anywhere in the column name. Added test in commit 9c44576 demonstrating:

  • `col@middle` ✅ works
  • `end@` ✅ works
  • `@start@end` ✅ works

The BRALITERAL token accepts any characters, so @ in the middle/end is fully supported with backticks.

Copilot AI changed the title Support @ symbol in qualified column names (table.@column) Support @ symbol in column names with backticks and qualified syntax Nov 19, 2025
Copilot finished work on behalf of mathiasrw November 19, 2025 13:48
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.

@ symbol in column name.

2 participants