Skip to content

feat(query): support quoted identifiers in cypher and sql - #121

Merged
prrao87 merged 2 commits into
mainfrom
feat/backtick-identifiers
Nov 4, 2026
Merged

prrao87 merged 2 commits into
mainfrom
feat/backtick-identifiers

Conversation

@prrao87

@prrao87 prrao87 commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Why

Labels, relationship types and columns whose names contain spaces or other characters, or match a keyword, can't be referenced today. Cypher identifiers only accept letters, digits and _, so a key column such as asset id is unreachable. Applications that build queries from a schema have to skip those columns.

This adds the standard quoting for each language: backticks in Cypher, as openCypher defines them, and double quotes in SQL, including inside GRAPH_TABLE as SQL/PGQ defines them.

What changed

Cypher. Any label, relationship type, variable, property name, map key or alias may be backtick-quoted:

MATCH (x:`Device Type`)-[:`PART OF`]->(`match`)
WHERE x.`asset id` IN $keys
RETURN x.`asset id` AS `asset id`, `match`.name AS `a``b`

A quoted name may contain any character and may match a keyword. Inside one, two backticks stand for one backtick. The quotes are removed while parsing, so planning, column resolution and output column names see the plain name (asset id, a`b). The existing case-insensitive matching is unchanged. Function names and $parameters stay unquoted.

SQL. The surrounding query already took double-quoted identifiers from DataFusion. Inside GRAPH_TABLE, double quotes now name identifiers too, and "" stands for one ":

SELECT g."asset id" FROM GRAPH_TABLE (
    MATCH (x:"Device Type") WHERE x.status = 'active'
    COLUMNS (x."asset id" AS "asset id")
) g

Backticks also work inside GRAPH_TABLE. The direct graph_table('...') call still takes Cypher text exactly as written.

Query results that change

Inside a GRAPH_TABLE (...) clause, "..." used to be a Cypher string literal. It is now an identifier, so strings there must use single quotes, as in the rest of the SQL query. WHERE a.name = "Alice" now compares against a property named Alice. No existing test or docs example used double-quoted strings in GRAPH_TABLE.

Docs

The Cypher guide gains a quoted-names section. The SQL guide now describes the GRAPH_TABLE body as Cypher with SQL's quoting. It also notes that SqlEngine registers table names in lowercase, so a quoted table name must be lowercase as well: "device type", not "Device Type".

Validation

  • New Rust and Python tests run with and without the CSR. They cover a label, relationship type and property containing spaces, keywords as variables and aliases (match, return, where, select), an escaped backtick, an inline property map, and SQL with double quotes in both the outer query and GRAPH_TABLE. A unit test covers the GRAPH_TABLE quote rewrite, including "", backticks inside double quotes, and a " inside a single-quoted string.
  • Locally: cargo test --workspace, cargo clippy --workspace --all-targets -- -D warnings, cargo fmt --check, the Python suite (1700 passed), ruff, pyright, typos and the strict docs build all pass.
  • Updated with main after fix(query): support bound string predicates and untyped relationships across labels #120 merged (it also changes the parser). On the combined code, Rust tests, Clippy and the Python suite (1706 passed) all pass.
  • CI is pending.

🤖 Generated with Claude Code

Cypher accepts backtick-quoted labels, relationship types, variables, property names and
aliases, as openCypher does: a quoted name may hold spaces or other characters, may match a
keyword, and writes a backtick as two. Inside GRAPH_TABLE, double quotes name identifiers as in
SQL/PGQ and the surrounding SQL, so strings there need single quotes.
@prrao87
prrao87 marked this pull request as ready for review November 4, 2026 01:34
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Deploying lance-csr with  Cloudflare Pages  Cloudflare Pages

Latest commit: 7b035b8
Status: ✅  Deploy successful!
Preview URL: https://c9426a3d.lance-csr.pages.dev
Branch Preview URL: https://feat-backtick-identifiers.lance-csr.pages.dev

View logs

@prrao87
prrao87 merged commit aeeddce into main Nov 4, 2026
8 checks passed
@prrao87
prrao87 deleted the feat/backtick-identifiers branch November 4, 2026 01:49
prrao87 added a commit that referenced this pull request Nov 4, 2026
Patch bump: #120 and #121 fix and extend query parsing without changing the Python or Rust API.
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.

1 participant