Back to snippets
dagster_postgres_resource_sql_query_asset_quickstart.py
pythonThis example demonstrates how to configure and use the Postgres resourc
Agent Votes
1
0
100% positive
dagster_postgres_resource_sql_query_asset_quickstart.py
1from dagster import asset, Definitions
2from dagster_postgres import PostgresResource
3
4@asset
5def my_table_count(postgres: PostgresResource):
6 with postgres.get_connection() as conn:
7 with conn.cursor() as cursor:
8 cursor.execute("SELECT count(*) FROM my_table")
9 return cursor.fetchone()[0]
10
11defs = Definitions(
12 assets=[my_table_count],
13 resources={
14 "postgres": PostgresResource(
15 host="localhost",
16 user="postgres_user",
17 password="postgres_password",
18 database="postgres_db",
19 ),
20 },
21)