PostgreSQL

  1. Connecting
    1. CLI
    2. Python API
  2. URLs
  3. Type Conversion
  4. Limitations and Constraints

Connecting

CLI

recap ls postgresql://user:pass@localhost:5432
recap schema postgresql://user:pass@localhost:5432/testdb/public/test_types

Python API

from recap.clients import create_client

with create_client("postgresql://user:pass@localhost:5432") as client:
    client.ls("testdb")
    client.schema("testdb", "public", "test_types")

URLs

Recap’s PostgreSQL client takes a PostgreSQL URL with an optional DB in the path.

postgresql://[username]:[password]@[host]:[port]/[database]/[schema]/[table]

The schema component is not a data model schema. It’s PostgreSQL’s schema, which is similar to a namespace. schema is usually public.

Type Conversion

PostgreSQL Type Recap Type
bigint, int8, bigserial, serial8 IntType (bits=64, signed=True)
integer, int, int4, serial, serial4 IntType (bits=32, signed=True)
smallint, smallserial, serial2 IntType (bits=16, signed=True)
double precision, float8 FloatType (bits=64)
real, float4 FloatType (bits=32)
boolean BoolType
text, json, jsonb, character varying, varchar StringType (bytes_=OCTET_LENGTH, variable=True)
char StringType (bytes_=OCTET_LENGTH, variable=False)
bytea, bit varying BytesType (bytes_=MAX_FIELD_SIZE, variable=True)
bit BytesType (bytes_=ceil(BIT_LENGTH / 8), variable=False)
timestamp IntType(bits=64, logical=”build.recap.Timestamp”, unit=unit)
decimal, numeric BytesType(logical=”build.recap.Decimal”, bytes_=32, variable=False, precision=NUMERIC_PRECISION, scale=NUMERIC_SCALE)

Limitations and Constraints

The conversion functions raise a ValueError exception if the conversion is not possible.