ralsei.task.create_table_sql

Module Contents

Classes

CreateTableSql

Runs a CREATE TABLE sql script

API

class ralsei.task.create_table_sql.CreateTableSql

Bases: ralsei.task.base.TaskDef

Runs a CREATE TABLE sql script

Variables passed to the template: table, view

Example

unnest.sql

CREATE TABLE {{table}}(
    id SERIAL PRIMARY KEY,
    name TEXT
);
{%-split-%}
INSERT INTO {{table}}(name)
SELECT json_array_elements_text(json->'names')
FROM {{sources}};

pipeline.py

"unnest": CreateTableSql(
    sql=Path("./unnest.sql").read_text(),
    table=Table("new_table"),
    locals={"sources": self.outputof("other")},
)

Note

You can use ralsei.utils.folder() to find SQL files relative to current file

sql : str | list[str] = None

Sql template strings

Individual statements must be either separated by {%split%} tag or pre-split into a list

table : ralsei.types.Table = None

Table being created

view : bool = False

whether this is a VIEW instead of a TABLE