Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf8df836

Browse files
committed
Adjust power() error messages to be more descriptive.
1 parent3159040 commitf8df836

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

‎src/backend/utils/adt/float.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.156 2008/05/0915:36:06 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.157 2008/05/0921:31:23 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1334,11 +1334,14 @@ dpow(PG_FUNCTION_ARGS)
13341334
* certain error conditions. Specifically, we don't return a divide-by-zero
13351335
* error code for 0 ^ -1.
13361336
*/
1337-
if ((arg1==0&&arg2<0)||
1338-
(arg1<0&&floor(arg2)!=arg2))
1337+
if (arg1==0&&arg2<0)
13391338
ereport(ERROR,
13401339
(errcode(ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION),
1341-
errmsg("invalid argument for power function")));
1340+
errmsg("zero raised to a negative power is undefined")));
1341+
if (arg1<0&&floor(arg2)!=arg2)
1342+
ereport(ERROR,
1343+
(errcode(ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION),
1344+
errmsg("a negative number raised to a non-integer power yields a complex result")));
13421345

13431346
/*
13441347
* pow() sets errno only on some platforms, depending on whether it

‎src/backend/utils/adt/numeric.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Copyright (c) 1998-2008, PostgreSQL Global Development Group
1515
*
1616
* IDENTIFICATION
17-
* $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.113 2008/05/0915:36:06 momjian Exp $
17+
* $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.114 2008/05/0921:31:23 momjian Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -1897,13 +1897,17 @@ numeric_power(PG_FUNCTION_ARGS)
18971897
* certain error conditions. Specifically, we don't return a divide-by-zero
18981898
* error code for 0 ^ -1.
18991899
*/
1900-
if ((cmp_var(&arg1,&const_zero)==0&&
1901-
cmp_var(&arg2,&const_zero)<0)||
1902-
(cmp_var(&arg1,&const_zero)<0&&
1903-
cmp_var(&arg2,&arg2_trunc)!=0))
1900+
if (cmp_var(&arg1,&const_zero)==0&&
1901+
cmp_var(&arg2,&const_zero)<0)
19041902
ereport(ERROR,
19051903
(errcode(ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION),
1906-
errmsg("invalid argument for power function")));
1904+
errmsg("zero raised to a negative power is undefined")));
1905+
1906+
if (cmp_var(&arg1,&const_zero)<0&&
1907+
cmp_var(&arg2,&arg2_trunc)!=0)
1908+
ereport(ERROR,
1909+
(errcode(ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION),
1910+
errmsg("a negative number raised to a non-integer power yields a complex result")));
19071911

19081912
/*
19091913
* Call power_var() to compute and return the result; note it handles

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp