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

  • Home
  • SEARCH
  • 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 1958024
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T07:57:38+00:00 2026-05-17T07:57:38+00:00

I’m getting an error from a deterministic PG function that seems dependent based on

  • 0

I’m getting an error from a deterministic PG function that seems dependent based on when I call it in a query.

The function is:

CREATE OR REPLACE FUNCTION ircm(starting_money numeric, value numeric, days numeric)
RETURNS numeric
AS $$
BEGIN
-- Calculate effective interest rate, compounded monthly.
    RETURN 12*(pow((value/starting_money),(1./(12.*(days/365.)))) - 1);
END;
$$ LANGUAGE plpgsql;

If I call it in a simple SELECT statement, it works fine:

SELECT ircm(100.00,60.427500643787215,30)
Result: -4.79925436505569765596

However, when I run that exact same call from a different SELECT statement using a subquery:

SELECT
    ircm(100.00,m.v::numeric,30) AS result
FROM(
    SELECT 60.427500643787215 AS v
) m

I get the error:

ERROR:  a negative number raised to a non-integer power yields a complex result
CONTEXT:  PL/pgSQL function "ircm" line 6 at RETURN

Since the calls are logically equivalent, how can PG be returning an error for one call, but not the other? I’ve made sure there’s only one definition of the function “ircm” in my database. I’ve tried dropping/adding it again to make sure PG isn’t somehow caching a corrupted definition.

  • 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-05-17T07:57:38+00:00Added an answer on May 17, 2026 at 7:57 am

    Which version and on which platform is your database running?

    Have you tried rewriting the function in SQL:

    CREATE OR REPLACE FUNCTION ircm(numeric, numeric, numeric)
    RETURNS numeric AS $$
        select 12 * (pow(($2 / $1), (1. / (12.* ($3 / 365.)))) - 1);
    $$ LANGUAGE sql immutable;
    

    I’m running v8.4.4 on Solaris, Linux, and Mac OS X and achieve the same results from your plpgsql (and my SQL) version called directly, and from within the subquery.

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

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
i want to parse a xhtml file and display in UITableView. what is the
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim

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.