Skip to content

Adapters

PostgreSQL

PostgreSQL adapter configuration for SQLBuild.

PostgreSQL requires the optional psycopg dependency:

pip install 'sqlbuild[postgres]'
# or
uv pip install 'sqlbuild[postgres]'
adapter = "postgres"
default_target = "dev"
[connections.postgres]
host = "localhost"
port = 5432
user = "my_user"
password = "my_password"
dbname = "my_database"
[targets.dev]
connection = "postgres"
database = "my_database"
schema = "analytics_dev"
Field Description
host PostgreSQL server hostname (default: localhost)
port PostgreSQL server port (default: 5432)
user Database user
password Database password
dbname Database name
temporary_test_functions false stops sqb test from creating session-temporary (pg_temp) copies of project SQL functions, so tests call the built functions. Use it behind a transaction-mode pooler such as PgBouncer, where later statements can run in a session without the copies (default: true)

Connection fields are passed to psycopg.connect(). See the psycopg documentation for all available options. The target remains authoritative for database and schema qualification.

adapter = "postgres"
[connections.postgres]
host = "localhost"
user = "my_user"
password = "${ENV:PG_PASSWORD}"
dbname = "analytics"
[targets.prod]
connection = "postgres"
database = "analytics"
schema = "prod"
[targets.dev]
connection = "postgres"
database = "analytics"
schema = "dev"

sqb test creates each SQL function the selected tests call in the session’s pg_temp schema and calls it as pg_temp.<name>, so tests use the current project definition without a build. Temporary functions belong to one server session: behind a transaction-mode pooler, run sqb test through a direct connection or a session-mode pool, or set temporary_test_functions = false so tests call the built functions. See Functions in sqb test.