Skip to main content
Version: 1.9.0

PostgresDest

class PostgresDest(
conn: PostgresConn,
destination_tables: str | list[str],
if_table_exists: IfTableExistStrategySpec = 'append',
transactional: bool = True,
chunk_size: PositiveInt = 100000,
loader: PostgresDestWriterSpec = 'polars_sqlalchemy',
)

Bases: DestinationPlugin

Categories: destination

Destination plugin for writing data to PostgreSQL.

Initialize a PostgresDest instance for writing data to PostgreSQL.

Parameters

parameter
conn

The Postgres connection configuration.

parameter
destination_tables

The tables to create. If multiple tables are provided, they must be provided as a list.

parameter
if_table_exists

The strategy to follow when the table already exists. Defaults to 'append'. - ‘replace’ will create a new database table, overwriting an existing one. - ‘append’ will append to an existing table.

parameter
transactional

Whether to use transactions for writing data to ensure consistency. Defaults to True

parameter
chunk_size

The chunk size for writing large results in batches. Defaults to 100000.

parameter
loader

The data processing loader to use for executing DB write operation.

Properties

property
chunk_sizeint

The chunk size for writing large results in batches.

property
connPostgresConn

The Postgres connection configuration.

property
destination_tableslist[str]

The table(s) to create. If multiple tables are provided, they must be provided as a list.

property
if_table_existsIfTableExistStrategySpec

The strategy to follow when the table already exists.

property
loaderPostgresDestWriterSpec

The data processing loader to use for executing DB write operation.

property
transactionalbool

Whether to use transactions for writing data to ensure consistency.

Methods

stream
def stream(working_dir: str, *results: list[LazyFrame | None])

Store the results into the PostgreSQL database.

Parameters:

parameter
working_dir

The working directory where the results are stored.

parameter
results

The results to store in the SQL destination.