Chalk supports PostgreSQL as a SQL source. You can configure the PostgreSQL-specific options using the PostgreSQLSource init args, or configure the source through your dashboard, and reference the source in your code.

Adding PostgreSQL

On the dashboard, you can plug in the configuration for your PostgreSQL database:

Add PostgreSQL

Add a PostgreSQL integration. These parameters will also be available as environment variables.

PostgreSQL
Environment

Learn more about Chalk's PostgreSQL Integration

Integrations Setup

After configuring your PostgreSQL integration in the dashboard, define your data sources in Python:

from chalk.sql import PostgreSQLSource

risk_pg = PostgreSQLSource(name="RISK_PG")
marketing_pg = PostgreSQLSource(name="MARKETING_PG")

Then reference them in SQL file resolvers using the name parameter. For example, to query from the RISK_PG source:

-- type: online
-- resolves: User
-- source: RISK_PG
SELECT id, credit_score FROM users

And to query from the MARKETING_PG source:

-- type: online
-- resolves: User
-- source: MARKETING_PG
SELECT id, email, campaign_status FROM users
Named integrations inject environment variables with the standard names prefixed by the integration name. For example, if your integration is called RISK_PG, then the variable PGPORT will be injected as RISK_PG_PGPORT.