Skip site navigation (1) Skip section navigation (2)

Re: How to truncate? integers

From: Leif Biberg Kristensen <leif(at)solumslekt(dot)org>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: How to truncate? integers
Date: 2011-11-16 21:30:10
Message-ID: 201111162230.11062.leif@solumslekt.org (view raw or flat)
Thread:
Lists: pgsql-novice
On Wednesday 16. November 2011 21.26.19 Johann Schatzer wrote:
> How can I ~truncate~ integers?
> 
> 
> this column
> 
> 4770
> 4780
> 4800
> 4810
> 4840
> 4900
> 4930
> 4950
> 4960
> 5070
> 5090
> 5130
> 
> should give
> 
> 4700
> 4700
> 4800
> 4800
> 4800
> 4900
> 4900
> 4900
> 4900
> 5000
> 5000
> 5100
> 
> thank you

Divide by 100, keep integer part, and multiply again by 100:

test=> select (4770/100)::integer * 100;
 ?column? 
----------
     4700
(1 row)

Time: 0,426 ms
test=> 

regards,
Leif

In response to

pgsql-novice by date

Next:From: Jean-Yves F. BarbierDate: 2011-11-16 21:35:52
Subject: Re: How to truncate? integers
Previous:From: Richard BroersmaDate: 2011-11-16 21:25:22
Subject: Re: How to truncate? integers

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group