
Just like other operations, CAST in PostgreSQL also has it's own DOs and DONTs. We can do it either writing: SELECT CAST(97 AS varchar) ĭifferent scenarios of CAST in PostgreSQL This means we need to convert an integer datatype to string datatype. Suppose we want the number 97 to be returned to us a String datatype. Instead of using the above syntax, we can also use the following condensed syntax: expression::type

Suppose we need to add 2 numbers stored in 2 columns of a row/record in a table. Let's understand why do we need the casting technique (or briefly the CAST operator) in PostgreSQL with a very simple yet practical example.

This article will illustrate the functions of CAST operator in PostgreSQL with hands-on examples.

We can perform various cast operations in PostgreSQL for converting one datatype to another, such as the String datatype to the Integer datatype (or the Boolean datatype or datetime datatype) and vice versa. Cast is a technique in PostgreSQL with which we can convert a value of one datatype into another.
