Agent: runsql

Historical names: run, sql

Runs SQL commands on target database

Advice: write re-applyable SQL commands

Syntax and samples

 - do: run
   file: precheck.sql

Mentioned file must be inside same directory.

-- precheck.sql
-- Mark syncing timestamp if not marked yet
UPDATE meta.registry
  SET synced_until_ts = '2024-01-01'
  WHERE task_id = 'from_arno.ods_arno.table_with_very_old_data'
  AND synced_until_ts IS NULL;

Tag "file" can be string or array of strings. In case of array files will be applied in defined order.

 - do: run
   file: 
    - precheck.sql
    - create.sql
    - index.sql

Remarks

  • During loading action changing content of some meta-tables is quite bad idea, but there are some use cases for that (eg. above example)
  • meta tables may by in schema "meta" or "bis" and may or may not have prefix "bis_", so in such use case be familiar with your version.
  • Creating empty tables is not good idea, but you may do: create table as ... to create and fullfill table,
  • Anyway don't forgot that SQL must be repeatable -- use IF NOT EXISTS or DROP IF EXISTS -- PostgreSQL support such conditions on most of objects