The CAST operator in PostgreSQL


Introduction

Cast is a technique in PostgreSQL with which we can convert a value of one datatype into another. 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. This article will illustrate the functions of CAST operator in PostgreSQL with hands-on examples.

Why do we need to CAST?

Let’s understand why do we need the casting technique (or briefly the CAST operator) in PostgreSQL with a very simple yet practical example. Suppose we need to add