Skip to content

Instantly share code, notes, and snippets.

@anna-geller
Created November 2, 2021 09:33
Show Gist options
  • Save anna-geller/fc29ea1e02113d6a6b20cbaa03ac315e to your computer and use it in GitHub Desktop.
Save anna-geller/fc29ea1e02113d6a6b20cbaa03ac315e to your computer and use it in GitHub Desktop.
from prefect import Flow, Parameter, task
from prefect.tasks.postgres import PostgresExecute
from prefect.tasks.secrets import PrefectSecret
postgres_execute = PostgresExecute(
db_name="abc", user="peter", host="my_host", port=5432,
)
@task
def define_query_from_param(param: str):
return f"INSERT INTO {param} VALUES (...)"
with Flow("postgres_example") as flow:
postgres_pwd = PrefectSecret("POSTGRES_PASSWORD")
table_name = Parameter("table_name", default="my_schema.my_table")
query = define_query_from_param(table_name)
postgres_execute(password=postgres_pwd, query=query)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment