ドキュメントメニュー

SQL#

Supernova は DuckDB 1.4-LTS を基にした読み取り専用の SQL 方言を受け付けます。レイクのテーブルは titan.<schema>.<table> または <schema>.<table> で参照します。どちらも組織のレイク内で解決されます。

sql
with ranked as (
  select
    customer,
    amount,
    row_number() over (partition by customer order by created_at desc) as recency
  from titan.stripe.charges
  where status = 'succeeded' and not _deleted
)
select * exclude (recency)
from ranked
qualify recency = 1

名前とスコープ#

titan はカタログの別名であり、物理的なレイク ID ではありません。物理 ID をクエリに記述することはできません。修飾のないリレーション名は、そのスコープ内の CTE と別名だけに解決されます。

空白を含む識別子やキーワードと重なる識別子には二重引用符を使います。文字列リテラルには一重引用符を使います。

利用可能なクエリ構造#

基本機能には CTE、内部結合と外部結合、using、ウィンドウ関数、qualifyunion allunion all by namedistinctorder bylimitoffset があります。アスタリスクの修飾子を使うと、列数の多いソーステーブルを扱いやすくなります。

sql
select * exclude (metadata, _synced_at)
replace (lower(email) as email)
from titan.hubspot.contacts
where not _deleted

リストのインデックスは 1 始まりです。JSON はキー、インデックス、JSON パスを指定した ->->> に対応します。高階のリスト関数は x -> expressionlambda x: expression の形式を受け付けます。

便利な組み込み関数として date_truncstrftimestrptimedate_diffepoch_mssplit_partregexp_extractregexp_replacestring_aggjson_extractunnestgenerate_serieslist_aggregate があります。

キャストと null#

cast(value as type) は変換できないと失敗します。try_cast(value as type) はその行に null を返します。is not distinct from は null を安全に扱う等価比較を提供します。

sql
select try_cast(property_annual_revenue as decimal(18, 2)) as annual_revenue
from titan.hubspot.companies

拒否される文#

クエリからレイクの状態を変更することはできません。insertupdatedeletemergedropaltertruncateattachcopyinstallload、トランザクション文、マクロ以外の create 文は、拒否した構文の名前を示す機能エラーを返します。

この方言は、ストアドプロシージャ、空間型、外部カタログ、ファイルの自動検出も拒否します。データの取り込みにはソース、永続的な派生テーブルにはモデル、送信先への書き込みには送信を使ってください。