Skip to content

Drivers

PostgreSQL's frontend/backend protocol allows column data to be encoded using two formats: Text or Binary.

Text is the most commonly used. It's the only option available for the simple query protocol and is often the default value for the extended query protocol (ie prepared statements, see DECLARE). COPY and logical replication also uses this format by default to exchange column data. The TCE extension will work seamlessly in that situation.

The Binary format is more efficient because it avoids the overhead of text serialization/deserialization (e.g., parsing "2024-01-15" as a date string vs. receiving raw bytes directly).

The TCE extension will not work out-of-box with drivers using the binary protocol. For that, you need to enable the tce.autocast parameter

ALTER DATABASE foo SET tce.autocast TO TRUE;

Here's a comprehensive list of the most commons drivers available and which protocol they implement:

Language Driver Protocol
C libpq Text and Binary (opt-in)
C# / .NET Npgsql Binary
Go pgx Binary
Java pgjdbc Binary (prepared statements only)
Node.js postgres (Porsager) Binary
Node.js node-postgres Text
Python asyncpg Binary
Python psycopg2 Text
Python psycopg3 Text and Binary (opt-in)
PHP pdo_pgsql Text
Ruby pg Text
Rust tokio-postgres Binary

opt-in means the driver defaults to the text protocol, but you can explicitly request binary mode in your code. For example with psycopg3:

cursor.execute("SELECT ...", binary=True)