Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8750927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:57:04+00:00 2026-06-13T12:57:04+00:00

I am using PostgreSQL via the Ruby gem ‘sequel’. I’m trying to round to

  • 0

I am using PostgreSQL via the Ruby gem ‘sequel’.

I’m trying to round to two decimal places.

Here’s my code:

SELECT ROUND(AVG(some_column),2)    
FROM table

I get the following error:

PG::Error: ERROR:  function round(double precision, integer) does 
not exist (Sequel::DatabaseError)

I get no error when I run the following code:

SELECT ROUND(AVG(some_column))
FROM table

Does anyone know what I am doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:57:05+00:00Added an answer on June 13, 2026 at 12:57 pm

    PostgreSQL does not define round(double precision, integer). For reasons @Mike Sherrill ‘Cat Recall’ explains in the comments, the version of round that takes a precision is only available for numeric.

    regress=> SELECT round( float8 '3.1415927', 2 );
    ERROR:  function round(double precision, integer) does not exist
    
    regress=> \df *round*
                               List of functions
       Schema   |  Name  | Result data type | Argument data types |  Type  
    ------------+--------+------------------+---------------------+--------
     pg_catalog | dround | double precision | double precision    | normal
     pg_catalog | round  | double precision | double precision    | normal
     pg_catalog | round  | numeric          | numeric             | normal
     pg_catalog | round  | numeric          | numeric, integer    | normal
    (4 rows)
    
    regress=> SELECT round( CAST(float8 '3.1415927' as numeric), 2);
     round 
    -------
      3.14
    (1 row)
    

    (In the above, note that float8 is just a shorthand alias for double precision. You can see that PostgreSQL is expanding it in the output).

    You must cast the value to be rounded to numeric to use the two-argument form of round. Just append ::numeric for the shorthand cast, like round(val::numeric,2).


    If you’re formatting for display to the user, don’t use round. Use to_char (see: data type formatting functions in the manual), which lets you specify a format and gives you a text result that isn’t affected by whatever weirdness your client language might do with numeric values. For example:

    regress=> SELECT to_char(float8 '3.1415927', 'FM999999999.00');
        to_char    
    ---------------
     3.14
    (1 row)
    

    to_char will round numbers for you as part of formatting. The FM prefix tells to_char that you don’t want any padding with leading spaces.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume that you have this code in C#/.NET (using PostgreSQL via ODBC): using System.Data.Odbc;
I am using Ruby to call postgresql through the shell via a command like:
I'm using PostgreSQL 9.1.13 Here is what I've done so far: /* First Array
I'm using Windows XP and I've installed PostgreSQL 8.3.5-2. I can create databases via
Ruby keeps segfaulting when using the Koala gem to talk over HTTP: /Users/pawel/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:799: [BUG]
Using PostgreSQL 8.4, I'm trying to put together the following query: SELECT (field_a +
There's an enterprise application using Java + Hibernate + PostgreSQL. Hibernate is configured via
I am trying to send input to a interactive command running via screen. Here
I have a Django-based webapp that is using PostgreSQL as the backend via psycopg2.
I am trying to create a Rails app that uses PostgreSQL. Here is a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.