Truncate the value of column in Postgresql (TRUNC() Function)

In order to truncate the value of column in postgresql we use TRUNC() function. TRUNC() Function in postgresql truncates the value. Let’s see how to

  • Truncate the value in postgresql – TRUNC()
  • Truncate the value to decimal places in postgresql
  • Create the column which truncates the value of the column

With an example for each

Get TRUNC() in Postgresql:

TRUNC() function in posgresql gets the truncated value

SELECT TRUNC(5.7) AS "Truncate_hindex";

So the truncated value will be

Truncate the value of column in Postgresql 2

 

SELECT TRUNC(5.69677,2) AS "Truncate_hindex";

The truncated value will be for two decimal places

Truncate the value of column in Postgresql 3

 

Get truncated value of column in Postgresql table:

We use table states

Truncate the value of column in Postgresql 1

SELECT *,TRUNC(hindex_score) as Truncate_hindex  from STATES

We have created a column and stored truncated value of hindex_score

So the resultant table will be

Truncate the value of column in Postgresql 4

 

Truncate the column to decimal places in Postgresql table:

Truncate the column to two decimal places as shown below

 SELECT *,TRUNC(hindex_score,2) as Truncate_hindex  from STATES

We have created a column and stored the truncated value of hindex_score to two decimal places

So the resultant table will be

Truncate the value of column in Postgresql 5