This article is half-done without your Comment! *** Please share your thoughts via Comment ***
In this post, I am sharing different options for data type casting of PostgreSQL.
I received a couple of queries on data type casting, so sharing available options for the beginner of PostgreSQL.
Please check the below available options:
In the below demonstration, I am converting string ‘188’ into integer and adding one in the result.
Option 1:
1 2 3 4 5 |
SELECT '188'::int4 + 1; ?column? ---------- 189 |
Option 2:
1 2 3 4 5 |
SELECT int4 '188' + 1; ?column? ---------- 189 |
Option 3:
1 2 3 4 5 |
SELECT int4('188') + 1; ?column? ---------- 189 |
Option 4:
1 2 3 4 5 |
SELECT CAST('188' AS int4)+1; ?column? ---------- 189 |
Leave a Reply