Vol. I · A Postgres HandbookTwelve chapters · · 756 queries

The Query & the Schema

A reading-room reference for writing PostgreSQL by hand — selects to window functions, with the schema in plain view.

FrontChaptersSchemaColophon
Chapters · Basic SELECT · Query 057 / 136
EasyBasic SELECT

Cast data types using :: syntax

The query

SQL
SELECT 
  '100'::INTEGER AS string_to_int,
  CURRENT_DATE::TEXT AS date_to_string,
  '2024-01-01'::DATE AS string_to_date;
Tested against PostgreSQL 16

Note

“The :: operator is PostgreSQL-specific syntax for casting. It is concise and widely used.

← Previous

Drop a constraint

Next →

Cast data types using CAST() standard

The Query & the Schema

Set in Fraunces and Inter Tight. Printed on parchment, in oxblood and ink. No tracking, no accounts, no JavaScript on the answer pages beyond what your browser needs to copy a query.

Compiled for Postgres 16 · MMXXVI