PostgreSQL table function

BETA

The Tinybird postgresql() table function is currently in public beta.

The Tinybird postgresql() table function allows you to read data from your existing PostgreSQL database into Tinybird, then schedule a regular Copy Pipe to orchestrate synchronization. You can load full tables, and every run performs a full replace on the Data Source.

To use it, define a node using standard SQL and the postgresql function keyword, then publish the node as a Copy Pipe that does a sync on every run. See Table functions for general information and tips.

Syntax

Create a new Pipe Node. Call the postgresql table function and pass the hostname and port, database, table, user, and password:

Example query logic
SELECT *
FROM postgresql(
  'aws-0-eu-central-1.TODO.com:3866',
  'postgres',
  'orders',
  {{tb_secret('pg_username')}},
  {{tb_secret('pg_password')}},
)

Publish this node as a Copy Pipe. You can choose to append only new data or replace all data.

Type support and inference

Here's a detailed conversion table:

PostgreSQL data typeTinybird data type
BOOLEANUInt8 or Bool
SMALLINTInt16
INTEGERInt32
BIGINTInt64
REALFloat32
DOUBLE PRECISIONFloat64
NUMERIC or DECIMALDecimal(p, s)
CHAR(n)FixedString(n)
VARCHAR (n)String
TEXTString
BYTEAString
TIMESTAMPDateTime
TIMESTAMP WITH TIME ZONEDateTime (with appropriate timezone handling)
DATEDate
TIMEString (since there is no direct TIME type)
TIME WITH TIME ZONEString
INTERVALString
UUIDUUID
ARRAYArray(T) where T is the array element type
JSONString or JSON
JSONBString
INETString
CIDRString
MACADDRString
ENUMEnum8 or Enum16
GEOMETRYString

Considerations

The following considerations apply to the postgresql() table function:

  • Tinybird doesn't support all PostgreSQL types directly, so some types are mapped to String in Tinybird, which is the most flexible type for arbitrary data.
  • For the NUMERIC and DECIMAL types, Decimal(p, s) in Tinybird requires specifying precision (p) and scale (s).
  • Time zone support in Tinybird's DateTime can be managed via additional functions or by ensuring consistent storage and retrieval time zones.
  • Some types like INTERVAL don't have a direct equivalent in Tinybird and are usually stored as String or decomposed into separate fields.

See also

Updated