SpacetimeDB icon indicating copy to clipboard operation
SpacetimeDB copied to clipboard

SQL parser breaks for columns named `position`

Open puttehi opened this issue 10 months ago • 1 comments

Hey, Apparently it's an invalid keyword,

TL;DR:

🪐spacetime-server>select * from transforms
 id | gameObjectId | position 
----+--------------+----------
 (0 rows)                     
Time: 1.79ms
🪐spacetime-server>select position from transforms
sql parser error: Expected (, found: from at Line: 1, Column 17
🪐spacetime-server>select positio from transforms
`positio` is not in scope
🪐spacetime-server>select gameObjectId from transforms
 gameObjectId 
--------------
 (0 rows)     
Time: 1.92ms
🪐spacetime-server>select id, gameObjectId from transforms
 id | gameObjectId 
----+--------------
 (0 rows)          
Time: 1.73ms
🪐spacetime-server>select id, gameObjectId, position from transforms
sql parser error: Expected (, found: from at Line: 1, Column 35

Server logs:

WARN /home/ubuntu/actions-runner-linux-x64-2.309.0/_work/SpacetimeDB/SpacetimeDB/crates/client-api/src/lib.rs:100: sql parser error: Expected (, found: from at Line: 1, Column 17

WARN /home/ubuntu/actions-runner-linux-x64-2.309.0/_work/SpacetimeDB/SpacetimeDB/crates/client-api/src/lib.rs:100: sql parser error: Expected (, found: from at Line: 1, Column 35 

First I spotted it on the client:

bundle.min.js:92063 Subscription failure for 2 queries!: sql parser error: Expected (, found: FROM at Line: 1, Column 17
Queries:
SELECT position FROM transforms WHERE gameObjectId = 38,SELECT velocity, acceleration, mass FROM rigidbodies WHERE gameObjectId = 38

Documentation leads to 0 results when searching for "position" from https://spacetimedb.com/docs/sql

puttehi avatar Mar 11 '25 22:03 puttehi

Our parser treats POSITION as a reserved function name. You can get around this by using quoted identifiers:

SELECT "position" FROM transforms

joshua-spacetime avatar Mar 12 '25 00:03 joshua-spacetime

I'm going to close this issue. @puttehi feel free to reopen if you're still having trouble!

bfops avatar Apr 02 '25 17:04 bfops