Skip to main content
This page is a formal grammar reference for Sync Rules: it shows the syntax accepted for parameter queries and data queries using railroad diagrams. This page complements the Supported SQL guide, which explains in prose what you can write, with examples and restrictions. When to use this page: If you need to check whether a construct is valid, see how parameter vs data query syntax differs, or you’re used to grammar specs, use the diagrams and the “Used by” / “References” links to navigate. For most users just getting started, see Supported SQL and the Sync Rules docs.

ParameterQuery

SELECT id FROM users WHERE id = token_parameters.user_id
ParameterQuery syntax diagram References: StaticParameterQuery, TableParameterQuery, TableValuedParameterQuery

TableValuedParameterQuery

SELECT value FROM json_each(token_parameters.tags)
TableValuedParameterQuery syntax diagram References: Identifier, JsonEachCall, SelectItem, WhereClause

TableParameterQuery

SELECT id, name FROM users WHERE org_id = token_parameters.org_id
TableParameterQuery syntax diagram References: Reference, SelectItem, WhereClause

StaticParameterQuery

SELECT token_parameters.user_id AS id
StaticParameterQuery syntax diagram References: SelectItem, WhereClause

DataQuery

SELECT id, name FROM users WHERE users.id = bucket.user_id
DataQuery syntax diagram References: Reference, SelectItem, WhereClause

SelectItem

name AS user_name
SelectItem syntax diagram References: Expression, Identifier

JsonEachCall

JSON_EACH(token_parameters.tags)
JsonEachCall syntax diagram References: Expression

WhereClause

users.id = bucket.user_id AND active = true
WhereClause syntax diagram References: Predicate, WhereClause

Predicate

status IS NOT NULL
Predicate syntax diagram References: Expression

Expression

price * quantity + tax
Expression syntax diagram

Operators

Binary operators supported in scalar expressions, listed from highest to lowest precedence.
PowerSync evaluates all binary operators with equal precedence (left to right). Use parentheses to control evaluation order.
PrecedenceOperatorsDescription
1||String concatenation
2* / %Multiplication, division, modulo
3+ -Addition, subtraction
4& | << >>Bitwise AND, OR, left/right shift
5< > <= >=Less than, greater than, etc.
6= !=Equal, not equal
References: PrimaryExpression, PropertyAccess

PropertyAccess

->'address'->>'city'
PropertyAccess syntax diagram References: IntegerLiteral, StringLiteral

Reference

users.id
Reference syntax diagram References: Identifier

CastExpression

CAST(age AS TEXT)
CastExpression syntax diagram References: Expression

FunctionCall

upper(name)
FunctionCall syntax diagram References: Expression, Reference

PrimaryExpression

(price + tax)
PrimaryExpression syntax diagram References: CastExpression, Expression, FunctionCall, NumericLiteral, Reference, StringLiteral

Lexical Rules

TokenExamplesRule
Identifieruser_id, MY_TABLE, "Column Name", "with ""quotes"" inside"[A-Z_] ([A-Z_0-9])*
StringLiteral'hello', 'it''s', ''"'" ([\x20-\x26] | [\x28-\x7E])* "'"
IntegerLiteral0, 42, 12345([0-9])+
NumericLiteral3.14, 42, 0.5([0-9])+ ("." ([0-9])+)?

Identifier

Bare identifiers are normalized to lower case and may contain letters, digits, and underscores. Double-quoted identifiers (“name”) allow any printable character and support escaped quotes ("").

StringLiteral

Single-quoted string literal. Embedded single quotes are escaped by doubling them (”).

IntegerLiteral

One or more decimal digits (0-9).

NumericLiteral

Decimal number: one or more digits with an optional fractional part (.digits).