Typecast date or timestamp to character in Postgresql

In order to typecast date or timestamp to character in postgresql we will be using cast() function. With the help of cast() function we will be able to typecast timestamp or date  to character in postgresql. Let’s see how to

  • Typecast date or timestamp to character in Postgresql

We will be using orders table.

Typecast date or timestamp to character in Postgresql 1

 

Typecast date or timestamp to character in Postgresql:

Method 1: Using :: to typecast

Column name followed by :: and followed by text is used to typecast received column.

select *,received::text as received_text from orders

So the resultant dataframe with received column typecasted will be

Typecast date or timestamp to character in Postgresql 2

 

Method 2: Using CAST()  function to typecast

CAST() function with Argument column_name as  text is used to typecast received column.


select *,cast(received as text) as received_text from orders

So the resultant dataframe with received column typecasted will be

Typecast date or timestamp to character in Postgresql 3