# Postgres Tasks


This module contains a collection of tasks for interacting with Postgres databases via the psycopg2 library.

# PostgresExecute

class

prefect.tasks.postgres.postgres.PostgresExecute

(db_name, user, host, port=5432, query=None, data=None, commit=False, **kwargs)[source]

Task for executing a query against a Postgres database.

Args:

  • db_name (str): name of Postgres database
  • user (str): user name used to authenticate
  • host (str): database host address
  • port (int, optional): port used to connect to Postgres database, defaults to 5432 if not provided
  • query (str, optional): query to execute against database
  • data (tuple, optional): values to use in query, must be specified using placeholder is query string
  • commit (bool, optional): set to True to commit transaction, defaults to false
  • **kwargs (dict, optional): additional keyword arguments to pass to the Task constructor

methods:                                                                                                                                                       

prefect.tasks.postgres.postgres.PostgresExecute.run

(query=None, data=None, commit=False, password=None)[source]

Task run method. Executes a query against Postgres database.

Args:

  • query (str, optional): query to execute against database
  • data (tuple, optional): values to use in query, must be specified using placeholder is query string
  • commit (bool, optional): set to True to commit transaction, defaults to false
  • password (str): password used to authenticate; should be provided from a Secret task
Returns:
  • None
Raises:
  • ValueError: if query parameter is None or a blank string
  • DatabaseError: if exception occurs when executing the query



# PostgresFetch

class

prefect.tasks.postgres.postgres.PostgresFetch

(db_name, user, host, port=5432, fetch="one", fetch_count=10, query=None, data=None, commit=False, **kwargs)[source]

Task for fetching results of query from Postgres database.

Args:

  • db_name (str): name of Postgres database
  • user (str): user name used to authenticate
  • host (str): database host address
  • port (int, optional): port used to connect to Postgres database, defaults to 5432 if not provided
  • fetch (str, optional): one of "one" "many" or "all", used to determine how many results to fetch from executed query
  • fetch_count (int, optional): if fetch = 'many', determines the number of results to fetch, defaults to 10
  • query (str, optional): query to execute against database
  • data (tuple, optional): values to use in query, must be specified using placeholder is query string
  • commit (bool, optional): set to True to commit transaction, defaults to false
  • **kwargs (dict, optional): additional keyword arguments to pass to the Task constructor

methods:                                                                                                                                                       

prefect.tasks.postgres.postgres.PostgresFetch.run

(fetch="one", fetch_count=10, query=None, data=None, commit=False, password=None)[source]

Task run method. Executes a query against Postgres database and fetches results.

Args:

  • fetch (str, optional): one of "one" "many" or "all", used to determine how many results to fetch from executed query
  • fetch_count (int, optional): if fetch = 'many', determines the number of results to fetch, defaults to 10
  • query (str, optional): query to execute against database
  • data (tuple, optional): values to use in query, must be specified using placeholder is query string
  • commit (bool, optional): set to True to commit transaction, defaults to false
  • password (str): password used to authenticate; should be provided from a Secret task
Returns:
  • records (tuple or list of tuples): records from provided query
Raises:
  • ValueError: if query parameter is None or a blank string
  • DatabaseError: if exception occurs when executing the query



This documentation was auto-generated from commit 4a4acb5
on October 23, 2020 at 16:22 UTC