Custom SQL

Full Refresh with Custom SQL

Using CLI Flags

# Using inline SQL
$ sling run --src-conn MY_SOURCE_DB \
  --src-stream 'select * from my_schema.my_table where status = "active"' \
  --tgt-conn MY_TARGET_DB \
  --tgt-object 'target_schema.target_table' \
  --mode full-refresh

# Using SQL from a file
$ sling run --src-conn MY_SOURCE_DB \
  --src-stream file:///path/to/query.sql \
  --tgt-conn MY_TARGET_DB \
  --tgt-object 'target_schema.target_table' \
  --mode full-refresh

Using Replication

Running with Sling: sling run -r /path/to/replication.yaml

replication.yaml
source: MY_SOURCE_DB
target: MY_TARGET_DB

defaults:
  mode: full-refresh

streams:
  my_schema.my_table.1:
    sql: |
      select 
        id,
        first_name,
        last_name,
        email,
        status
      from my_schema.my_table 
      where status = 'active'
    object: target_schema.active_users

  my_schema.my_table.2:
    sql: file:///path/to/query.sql
    object: target_schema.custom_table

Incremental with Custom SQL

Using CLI Flags

Using Replication

Running with Sling: sling run -r /path/to/replication.yaml

The examples above demonstrate:

  • Using both inline SQL and SQL files

  • Joining multiple tables in custom SQL

  • Using incremental variables ({incremental_value} and {incremental_where_cond}). See here for details.

  • Handling duplicates with window functions

  • Overriding default primary keys and update keys

Custom-SQL Chunking

Combine custom SQL queries with chunking using the {incremental_where_cond} variable in your SQL. See the chunking documentation for details.

Last updated

Was this helpful?