Skip to main content

Casting

Certain data types can be cast to and from other types implicitly or explicitly.

  • 🟢 Implicit: Values can be automatically converted to the target type.
  • 🟠 Assignment: Values can be automatically converted when inserted to a column of the target type.
  • 🔷 Explicit: Values can be converted to the target type only when you use the cast function or the :: operator.
From \ Tobooleansmallintintegerbigintnumericrealdoublevarchardatetimestamptimestamp with time zonetimeinterval
boolean✖️🔷✖️✖️✖️✖️🟠✖️✖️✖️✖️✖️
smallint✖️🟢🟢🟢🟢🟢🟠✖️✖️✖️✖️✖️
integer🔷🟠🟢🟢🟢🟢🟠✖️✖️✖️✖️✖️
bigint✖️🟠🟠🟢🟢🟢🟠✖️✖️✖️✖️✖️
numeric✖️🟠🟠🟠🟢🟢🟠✖️✖️✖️✖️✖️
real✖️🟠🟠🟠🟠🟢🟠✖️✖️✖️✖️✖️
double✖️🟠🟠🟠🟠🟠🟠✖️✖️✖️✖️✖️
varchar🔷🔷🔷🔷🔷🔷🔷🔷🔷🔷🔷🔷
date✖️✖️✖️✖️✖️✖️✖️🟠🟢🟢✖️✖️
timestamp✖️✖️✖️✖️✖️✖️✖️🟠🟠🟢🟠✖️
timestamp with time zone✖️✖️✖️✖️✖️✖️✖️🟠🟠🟠🟠✖️
time✖️✖️✖️✖️✖️✖️✖️🟠✖️✖️✖️🟢
interval✖️✖️✖️✖️✖️✖️✖️🟠✖️✖️✖️🟠
note

Structs can be casted to structs explicitly or implicitly if the nested expressions and types can be casted.

Help us make this doc better!