Skip to main content

Postgres Reference

Authentication options and data type handling for Postgres connections.

Authentication

VariableExampleDescription
DATACONTRACT_POSTGRES_USERNAMEpostgresUsername
DATACONTRACT_POSTGRES_PASSWORDmysecretpasswordPassword

host, port (default 5432), database, and schema come from the contract's servers block.

Data types

Importing

datacontract import sql --dialect postgres maps DDL types as follows; the normalized SQL type is kept as physicalType.

Postgres typelogicalType
VARCHAR, CHAR, TEXTstring (maxLength for varchar/char)
SMALLINT, INT, INTEGER, BIGINTinteger
NUMERIC, DECIMAL, REAL, DOUBLE PRECISION, MONEYnumber
BOOLEANboolean
DATEdate
TIMEtime
TIMESTAMP, TIMESTAMPTZtimestamp
BYTEAstring (format binary)
JSONobject
XMLstring
UUID, SERIAL, BIGSERIAL, JSONB, INTERVAL, INET, array types (INT[])(unset)physicalType is still written

Testing

Postgres supports native type introspection: the declared physicalType is checked against information_schema.columns. Note that on Postgres text and varchar are distinct types — declare the one the column actually has. decimal and numeric are interchangeable, as are timezone variants of timestamps; length/precision is only enforced when declared (varchar matches varchar(255), varchar(255) does not match varchar(100)). A physicalType that isn't valid Postgres SQL falls back to the logical type category comparison.

The same applies to Postgres-compatible databases tested with type: postgres (e.g. RisingWave).

Logical type mapping

When no physicalType is declared, the CLI derives the native type from the logicalType — for example in datacontract export sql and the dbt exports. This table is generated from the converter in the CLI's code:

logicalTypePostgres type
stringtext
integerinteger
numbernumeric
booleanboolean
datedate
timestamptimestamptz
timetime
objectjsonb
arraytext[]