Back to Chapters
Chapter Progress: 0 %0 / 5 Lessons Read
‹›

4. Meet Dataform: SQL pipelines made tidy

4.3 Your first SQLX file: config and SELECT

Highlights & notes

Select lesson text to highlight it, or tap Add note.

    Bookmarks

    Bookmark a lesson to see it here.

      An SQLX file is a normal SQL SELECT with a small note on top. The note is the config block. It tells Dataform what to build from the query.

      The most used types:

      • type: "table": build a table. It is rebuilt fully on each run.
      • type: "view": build a view. No data is stored.
      • type: "incremental": add only new rows on each run. A later lesson covers it.

      You never write CREATE TABLE. You write only the SELECT. Dataform adds the CREATE OR REPLACE part during compilation, the step that turns SQLX into plain SQL.

      SQL vs SQLX

      • SQL: CREATE OR REPLACE TABLE silver.orders AS SELECT ...
      • SQLX: config { type: "table" } and then SELECT ...
      • The file name becomes the table name: orders.sqlx builds the table orders
      Must Know:

      Add a description to every table. Strict teams reject files without one. It appears in BigQuery and in the catalog, so the next person knows what the table is for.

      How it fits together

      1. config: what to build
      2. SELECT: which rows
      3. Compile → plain SQL

      A view with a description

      This file is saved as definitions/delivered_orders.sqlx.

      SQLX

      config {  type: "view",  schema: "silver",  description: "Delivered orders only",  tags: ["daily"]}SELECT  order_id,  amountFROM ${ref("orders_raw")}WHERE status = 'delivered'

      Result

      CREATE OR REPLACE VIEW `shop-dev.silver.delivered_orders` AS
      SELECT
        order_id,
        amount
      FROM `shop-raw.bronze.orders_raw`
      WHERE status = 'delivered'

      Try it yourself

      1. In definitions/, create a file named first_view.sqlx.
      2. Type config { type: "view" } and, under it, SELECT 1 AS id, 'hello' AS note.
      3. Look at the compiled query on the right side of the editor. Then click Start execution and find the new view in BigQuery.

      Question 1 · Easy

      What does the config block do?

      Question 2 · Medium

      The file definitions/daily_sales.sqlx has type: "table" and no name in its config. What is the table called?

      Question 3 · Hard

      You change type: "table" to type: "view" and run the file. What changes in BigQuery?

      Key takeaways

      An SQLX file is a config block plus a SELECT. The type says what to build, the file name becomes the table name, and compilation adds the CREATE statement for you.

      Lesson 18 of 90

      Save your progress

      Start free and your progress, code and notes stay saved. Free for 1 month, no card needed.

      Start free Log in
      PreviousYour first SQLX file: config and SELECT
      Save your progress free for 1 month. Start free · Log in