Module Contents

class airflow.hooks.postgres_hook.PostgresHook(*args, **kwargs)[source]


Interact with Postgres. You can specify ssl parameters in the extra field of your connection as {"sslmode": "require", "sslcert": "/path/to/cert.pem", etc}.

Note: For Redshift, use keepalives_idle in the extra connection parameters and set it to less than 300 seconds.

conn_name_attr = postgres_conn_id[source]
default_conn_name = postgres_default[source]
supports_autocommit = True[source]
copy_expert(self, sql, filename, open=open)[source]

Executes SQL using psycopg2 copy_expert method. Necessary to execute COPY command without access to a superuser.

Note: if this method is called with a “COPY FROM” statement and the specified input file does not exist, it creates an empty file and no data is loaded, but the operation succeeds. So if users want to be aware when the input file does not exist, they have to check its existence by themselves.

bulk_load(self, table, tmp_file)[source]

Loads a tab-delimited file into a database table

bulk_dump(self, table, tmp_file)[source]

Dumps a database table into a tab-delimited file

static _serialize_cell(cell, conn)[source]

Postgresql will adapt all arguments to the execute() method internally, hence we return cell without any conversion.

See for more information.

  • cell (object) – The cell to insert into the table

  • conn (connection object) – The database connection


The cell

Return type