Columns

Casting Columns

When running a replication, you can specify the column types to tell Sling to cast the data to the correct type. It is not necessary to include all columns. Sling will automatically detect the types for any unspecified columns.

Acceptable data types are:

  • bigint

  • bool

  • datetime

  • decimal or decimal(precision, scale) (such as decimal(10, 2))

  • integer

  • json

  • string or string(length) (such as string(100))

  • text or text(length) (such as text(3000))

Using CLI Flags

# template
sling run --columns '{ "<column_name>": "<data_type>" }'

# cast column to bigint
sling run --columns '{ "my_column": "bigint" }'

# cast column to decimal(10, 2)
sling run --columns '{ "my_column": "decimal(10, 2)" }'

# cast multiple columns
sling run --columns '{ "my_column": "string(150)", "my_other_column": "decimal(10, 2)" }'

# cast all columns to string
sling run --columns '{ "*": "string" }'

Using YAML

Using the defaults and streams keys, you can specify different columns for each stream.

source: source_name
target: target_name

defaults:
  # apply to all streams by default
  columns:
    id: bigint

streams:
  # inherit defaults
  my_stream:

  my_other_stream:
    # apply to this stream only (overrides defaults)
    columns:
      id: bigint
      my_column: string(150)
      my_other_column: decimal(10, 2)

  # cast all columns to string
  another_stream:
    columns:
      "*": string

Last updated