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 8465103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:56:48+00:00 2026-06-10T14:56:48+00:00

In PostgreSQL I’m getting the error: ERROR: argument for function exp too big SQL

  • 0

In PostgreSQL I’m getting the error:

ERROR: argument for function "exp" too big
SQL state: 22003

I need to write a stored procedude for the Exponential as:

  • If exp(value) throws argument for function “exp” too big
  • then return 0
  • else return exp(value)

Please help me how to process this stored procedure.

  • 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-10T14:56:49+00:00Added an answer on June 10, 2026 at 2:56 pm

    This is what’s happening:

    regress=# SELECT exp(NUMERIC '6000');
    ERROR:  argument for function "exp" too big
    

    You’re passing an unrealistically large value to exp(). It’s way too big to overflow a float8 (double) and can only be represented as a NUMERIC. Even there, there’s a limit, and you hit it when you go above exp(5999).

    For hard maths you might want to try PL/R, an in-database embedded version of the R language.

    It’s hard to say what to do, because you haven’t really explained what the query is for, what the inputs to exp are supposed to be, etc.

    Returning zero for an exponent that’s too big is kind of crazy. Why?


    To trap an exception, use BEGIN … EXCEPTION in PL/PgSQL.

    I’ve written the below function to return NaN (“not a number”) instead of zero, as I think returning zero is just downright wrong. Change it if you need to. It might also make a little bit of sense to return NULL.

    CREATE OR REPLACE FUNCTION exp_if_possible(numeric) RETURNS numeric as $$
    BEGIN
        RETURN exp($1);
    EXCEPTION
        WHEN numeric_value_out_of_range THEN
            RETURN 'NaN';
    END;
    $$ LANGUAGE 'plpgsql' IMMUTABLE;
    

    The error code numeric_value_out_of_range was obtained by looking up the SQLSTATE 22003 you get from the out-of-range exp in Appendix A. PostgreSQL Error Codes in the Pg manual. You’ll see a link to it in the documentation about BEGIN ... EXCEPTION.


    I initially said that if it’s to be done at all it should be done by testing the input, but I think I was wrong about that. There’s no guarantee that the limit will be exp(6000), so you’re right to use exception handling even though it’ll be slow and clumsy. I’ll update this response with an exception handling version in a sec.

    CREATE OR REPLACE FUNCTION crazy_exp(numeric) RETURNS numeric AS $$
    -- exp(6000) and above will throw 'argument for function "Exp" too big
    -- For such cases, return zero because [insert explanation here]
    SELECT CASE WHEN $1 < 6000 THEN exp($1) ELSE 0 END;
    $$ LANGUAGE 'sql' IMMUTABLE;
    
    CREATE OR REPLACE FUNCTION crazy_exp(float8) RETURNS float8 AS $$
    -- float8 goes out-of-range above about exp(600)
    SELECT CASE WHEN $1 <= 600 THEN exp($1) ELSE 0 END;
    $$ LANGUAGE 'sql' IMMUTABLE;
    

    That’s massively more efficient than trapping the “out of range” exception in PL/PgSQL, and makes your intent clearer too.

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

Sidebar

Related Questions

In postgresql, I need to insert data to, say table B from sql query
PostgreSQL is about to make me punch small animals. I'm doing the following SQL
Usually I worked with PostgreSQL and never had a problem, but now I need
I'm using PostgreSQL 9.1.3 and the following functions: CREATE OR REPLACE FUNCTION cad(INOUT args
Sometimes postgresql raise error deadlocks. In trigger for table setted FOR UPDATE. Table comment:
In PostgreSQL 8.4.3, I get this error when logging on to one of my
PostgreSQL 8.4 on Linux. I have a function: CREATE OR REPLACE FUNCTION production.add_customer (
postgresql python I need some help fixing some issues with a postgresql database I
Using PostgreSQL (8.x), I need to skip a block of sequence numbers automatically ,
In PostgreSQL, there is this very useful string_agg function, that allows query like: SELECT

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.