Typecast string or character to integer in Postgresql

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

  • Typecast string or character to integer in Postgresql

We will be using orders_new table.

Typecast string to numeric or integer in Postgresql 1

 

Typecast string or character to integer in Postgresql:

Method 1: Using :: to typecast

Column name followed by :: and followed by integer is used to typecast cno_text column.


select *,cno_text::integer as cno_int from orders_new

So the resultant dataframe with cno_text column typecasted will be

Typecast string to numeric or integer in Postgresql 2

 

Method 2: Using CAST()  function to typecast

CAST() function with Argument column_name as  integer is used to typecast cno_text column.


select *,cast(cno_text as integer) as cno_int from orders_new

So the resultant dataframe with cno_text column typecasted will be

Typecast string to numeric or integer in Postgresql 3