SQL reference

Language basics

Identifiers, qualification, literals, comments, aliases and naming rules.

Identifiers

Unquoted identifiers are case-insensitive. VegaDB normalizes them for lookup, so Orders, orders and ORDERS refer to the same unquoted name. Double-quoted identifiers preserve spelling and allow spaces, punctuation or reserved words.

SELECT order_id FROM sales.orders;
SELECT "Order ID" FROM "Imported Orders";

Do not use single quotes for identifiers. Single quotes always delimit string literals.

Qualified names

Objects use catalog.schema.object qualification. The current catalog and schema fill omitted parts.

SELECT * FROM lakehouse.sales.orders;
SELECT * FROM sales.orders;
SELECT * FROM orders;

Use fully qualified names in shared views and production SQL when the intended catalog must not depend on session state. USE catalog.schema changes resolution for later unqualified names in the same session.

Aliases

AS is optional for table and expression aliases, but including it for result columns improves readability.

SELECT o.customer_id, sum(o.net_amount) AS revenue
FROM lakehouse.sales.orders AS o
GROUP BY o.customer_id;

A prefix alias can place the alias before an expression where that form is supported:

SELECT revenue: sum(net_amount), order_month: date_trunc('month', ordered_at)
FROM sales.orders
GROUP BY order_month;

Literals

KindExamplesNotes
String'paid', 'Raja''s order'Escape a quote by doubling it.
BooleanTRUE, FALSECase-insensitive keywords.
NULLNULLUntyped until bound by context or cast.
Integer42, -9000Smallest compatible integer type is selected during binding.
Decimal12.50, DECIMAL '12.50'Cast explicitly when precision and scale are contractual.
Floating point1.2e6, DOUBLE 'NaN'Floating-point values are approximate.
Date/timeDATE '2026-09-03', TIMESTAMPTZ '2026-09-03 10:00:00+04:00'Typed forms avoid locale-dependent parsing.
IntervalINTERVAL '15 minutes', INTERVAL 3 DAYMonths, days and sub-day time remain distinct components.
List[1, 2, 3]Elements must have a common type.
Struct{name: 'Mira', active: true}Field names become part of the bound struct type.

Use CAST or a typed literal at application boundaries rather than relying on inference from text.

Comments

-- One-line comment
SELECT order_id /* explanation inside a statement */
FROM sales.orders;

Comments are SQL text. Do not place credentials, tokens or other secrets in them.

Reserved words

Language keywords such as SELECT, FROM, WHERE, GROUP, ORDER, TABLE, VIEW, USER and ROLE should not be used as unquoted object names. Quote a legacy name only when renaming it is impractical.

SELECT "group" FROM imported_data;

Name resolution

VegaDB resolves a reference in this order:

  1. Explicit catalog, schema and object components.
  2. The session's current catalog and schema.
  3. Columns visible from the current query scope, including legal outer correlations.
  4. Projection aliases only in clauses where alias lookup is defined, such as ORDER BY and supported QUALIFY expressions.

Ambiguous column references fail. Qualify the column with its relation alias instead of depending on source order.

Statement terminators

A semicolon terminates a statement. Drivers may send a single statement without a trailing semicolon. Credential-bearing CREATE PERSISTENT SECRET is restricted to a dedicated simple-query request and must not be combined with other statements.

Vegalake, VegaDB and VegaFlow are trademarks or registered trademarks of Vegalake Inc.

On this page