| :py:mod:`airflow.providers.postgres.hooks.postgres` |
| =================================================== |
| |
| .. py:module:: airflow.providers.postgres.hooks.postgres |
| |
| |
| Module Contents |
| --------------- |
| |
| Classes |
| ~~~~~~~ |
| |
| .. autoapisummary:: |
| |
| airflow.providers.postgres.hooks.postgres.PostgresHook |
| |
| |
| |
| |
| Attributes |
| ~~~~~~~~~~ |
| |
| .. autoapisummary:: |
| |
| airflow.providers.postgres.hooks.postgres.CursorType |
| |
| |
| .. py:data:: CursorType |
| |
| |
| |
| |
| .. py:class:: PostgresHook(*args, **kwargs) |
| |
| Bases: :py:obj:`airflow.hooks.dbapi.DbApiHook` |
| |
| Interact with Postgres. |
| |
| You can specify ssl parameters in the extra field of your connection |
| as ``{"sslmode": "require", "sslcert": "/path/to/cert.pem", etc}``. |
| Also you can choose cursor as ``{"cursor": "dictcursor"}``. Refer to the |
| psycopg2.extras for more details. |
| |
| Note: For Redshift, use keepalives_idle in the extra connection parameters |
| and set it to less than 300 seconds. |
| |
| Note: For AWS IAM authentication, use iam in the extra connection parameters |
| and set it to true. Leave the password field empty. This will use the |
| "aws_default" connection to get the temporary token unless you override |
| in extras. |
| extras example: ``{"iam":true, "aws_conn_id":"my_aws_conn"}`` |
| For Redshift, also use redshift in the extra connection parameters and |
| set it to true. The cluster-identifier is extracted from the beginning of |
| the host field, so is optional. It can however be overridden in the extra field. |
| extras example: ``{"iam":true, "redshift":true, "cluster-identifier": "my_cluster_id"}`` |
| |
| :param postgres_conn_id: The :ref:`postgres conn id <howto/connection:postgres>` |
| reference to a specific postgres database. |
| |
| .. py:attribute:: conn_name_attr |
| :annotation: = postgres_conn_id |
| |
| |
| |
| .. py:attribute:: default_conn_name |
| :annotation: = postgres_default |
| |
| |
| |
| .. py:attribute:: conn_type |
| :annotation: = postgres |
| |
| |
| |
| .. py:attribute:: hook_name |
| :annotation: = Postgres |
| |
| |
| |
| .. py:attribute:: supports_autocommit |
| :annotation: = True |
| |
| |
| |
| .. py:method:: get_conn(self) |
| |
| Establishes a connection to a postgres database. |
| |
| |
| .. py:method:: copy_expert(self, sql, filename) |
| |
| 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. |
| |
| |
| .. py:method:: get_uri(self) |
| |
| Extract the URI from the connection. |
| :return: the extracted uri. |
| |
| |
| .. py:method:: bulk_load(self, table, tmp_file) |
| |
| Loads a tab-delimited file into a database table |
| |
| |
| .. py:method:: bulk_dump(self, table, tmp_file) |
| |
| Dumps a database table into a tab-delimited file |
| |
| |
| .. py:method:: get_iam_token(self, conn) |
| |
| Uses AWSHook to retrieve a temporary password to connect to Postgres |
| or Redshift. Port is required. If none is provided, default is used for |
| each service |
| |
| |
| .. py:method:: get_table_primary_key(self, table, schema = 'public') |
| |
| Helper method that returns the table primary key |
| |
| :param table: Name of the target table |
| :param schema: Name of the target schema, public by default |
| :return: Primary key columns list |
| :rtype: List[str] |
| |
| |
| |