Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to convert a value of Double Precision to Bigint with PostgreSQL. How can I do that?

I have tried with to_bigint(myvalue) but that function didn't exist.

share|improve this question
up vote 15 down vote accepted

There are two ways to typecast in Postgres:

You either do it the SQL standard way:

select cast(3.141593 as bigint);

or you could use the Postgres-specific cast operator: ::

select (3.141593 :: bigint);

You might also want to consider the various rounding functions.

share|improve this answer
2  
+1 for linking to the manual – a_horse_with_no_name Jun 22 '11 at 11:23
    
@eevar Just a note from the docs, the rounding functions return type is "same as input," so if the type is important, casts are required. – shortstuffsushi Aug 19 '15 at 21:34
    
Looks like CAST actually does rounding – Andrew Wolfe Mar 17 at 19:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.