Skip to main content
Version: 1.8.0

PostgresSrc

class PostgresSrc(
conn: PostgresConn,
queries: QueriesSpec,
initial_values: dict[str, Any] | None = None,
transactional: bool = True,
chunk_size: PositiveInt = 100000,
loader: PostgresSrcLoaderSpec = 'polars_sqlalchemy',
schema_overrides: SchemaOverrideSpec = None,
)

Bases: SourcePlugin

Categories: source

Source plugin for reading data from Postgres.

Initialize a PostgresSrc instance for reading data from Postgres.

Parameters

parameter
conn

The Postgres connection configuration.

parameter
queries

The SQL query or list of queries to execute.

parameter
initial_values

Initial values for query parameters. Defaults to None.

parameter
transactional

Whether to use transactions for reading to ensure consistency. Defaults to True.

parameter
chunk_size

The chunk size in records for reading large queries in batches. Defaults to 100000.

parameter
loader

The data processing loader to use for executing SQL imports.

parameter
schema_overrides

Type mapping overrides for the columns of the queries. It can be a single mapping, a dictionary of mappings or a list of mappings. It can be a single dictionary mapping only when the queries is a single query. If using a dictionary of mappings, the keys must match any of names of the Tabsdata tables produced by the publisher. If using a list of mappings, the list of mappings must have the same size as the queries list; for queries there is no need for mapping the corresponding element in the list can be None. The mapping dictionary must have column names from the corresponding query as keys and the TableFrame DataType to cast the column to. The type casting from the original column type to the desired type must be supported.

Properties

property
chunk_sizeint

The chunk size in records for reading large queries in batches.

property
connPostgresConn

The Postgres connection configuration.

property
initial_valuesdict

The initial values for the parameters in the SQL queries.

property
loaderPostgresSrcLoaderSpec

The data processing loader to use for executing SQL imports.

property
querieslist[str]

The SQL queries to execute to read data.

property
schema_overrideslist[dict[str, DataType]] | None

The schema overrides for the tables being read.

property
transactionalbool

Whether to use transactions for reading to ensure consistency.

Methods

stream
def stream(working_dir: str) -> list[TableFrame]

Execute the query and load the results as a list of TableFrames.

Parameters:

parameter
working_dir

The directory where the Parquet files will be saved.

Returns:

A list of TableFrames containing the query results.