diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 139c81effc3727ab630bef56727ee9f6547601b2..9042cd394e16037cc05c468675986b39884daf6c 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -1,5 +1,5 @@ <!-- -$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.197 2004/04/10 18:02:59 momjian Exp $ +$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.198 2004/04/23 20:32:19 neilc Exp $ PostgreSQL documentation --> @@ -587,6 +587,14 @@ PostgreSQL documentation <entry><literal>-42</literal></entry> </row> + <row> + <entry><literal><function>ceiling</function>(<type>dp</type> or <type>numeric</type>)</literal></entry> + <entry>(same as input)</entry> + <entry>smallest integer not less than argument (alias for <function>ceil</function>)</entry> + <entry><literal>ceiling(-95.3)</literal></entry> + <entry><literal>-95</literal></entry> + </row> + <row> <entry><literal><function>degrees</function>(<type>dp</type>)</literal></entry> <entry><type>dp</type></entry> @@ -654,20 +662,20 @@ PostgreSQL documentation </row> <row> - <entry><literal><function>pow</function>(<parameter>a</parameter> <type>dp</type>, + <entry><literal><function>power</function>(<parameter>a</parameter> <type>dp</type>, <parameter>b</parameter> <type>dp</type>)</literal></entry> <entry><type>dp</type></entry> <entry><parameter>a</> raised to the power of <parameter>b</parameter></entry> - <entry><literal>pow(9.0, 3.0)</literal></entry> + <entry><literal>power(9.0, 3.0)</literal></entry> <entry><literal>729</literal></entry> </row> <row> - <entry><literal><function>pow</function>(<parameter>a</parameter> <type>numeric</type>, + <entry><literal><function>power</function>(<parameter>a</parameter> <type>numeric</type>, <parameter>b</parameter> <type>numeric</type>)</literal></entry> <entry><type>numeric</type></entry> <entry><parameter>a</> raised to the power of <parameter>b</parameter></entry> - <entry><literal>pow(9.0, 3.0)</literal></entry> + <entry><literal>power(9.0, 3.0)</literal></entry> <entry><literal>729</literal></entry> </row> diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h index 82900e55f340db36b18a6e3698e18e78821d9053..50eea65169b2dfd121c6961c2186a67c3e65250f 100644 --- a/src/include/catalog/catversion.h +++ b/src/include/catalog/catversion.h @@ -37,7 +37,7 @@ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.223 2004/04/01 21:28:45 tgl Exp $ + * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.224 2004/04/23 20:32:19 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -53,6 +53,6 @@ */ /* yyyymmddN */ -#define CATALOG_VERSION_NO 200403291 +#define CATALOG_VERSION_NO 200404220 #endif diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h index 5db922084ff65c360b8119a6da86567d0f67ced7..f4998eee572e9b67fbb24f6ed2fc2dd0f17da400 100644 --- a/src/include/catalog/pg_proc.h +++ b/src/include/catalog/pg_proc.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.324 2004/04/02 23:14:08 tgl Exp $ + * $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.325 2004/04/23 20:32:19 neilc Exp $ * * NOTES * The script catalog/genbki.sh reads this file and generates .bki @@ -471,6 +471,8 @@ DATA(insert OID = 229 ( dtrunc PGNSP PGUID 12 f f t f i 1 701 "701" _null_ DESCR("truncate to integer"); DATA(insert OID = 2308 ( ceil PGNSP PGUID 12 f f t f i 1 701 "701" _null_ dceil - _null_ )); DESCR("smallest integer >= value"); +DATA(insert OID = 2320 ( ceiling PGNSP PGUID 12 f f t f i 1 701 "701" _null_ dceil - _null_ )); +DESCR("smallest integer >= value"); DATA(insert OID = 2309 ( floor PGNSP PGUID 12 f f t f i 1 701 "701" _null_ dfloor - _null_ )); DESCR("largest integer <= value"); DATA(insert OID = 2310 ( sign PGNSP PGUID 12 f f t f i 1 701 "701" _null_ dsign - _null_ )); @@ -1667,6 +1669,8 @@ DATA(insert OID = 1345 ( cbrt PGNSP PGUID 12 f f t f i 1 701 "701" _null_ DESCR("cube root"); DATA(insert OID = 1346 ( pow PGNSP PGUID 12 f f t f i 2 701 "701 701" _null_ dpow - _null_ )); DESCR("exponentiation"); +DATA(insert OID = 1368 ( power PGNSP PGUID 12 f f t f i 2 701 "701 701" _null_ dpow - _null_ )); +DESCR("exponentiation"); DATA(insert OID = 1347 ( exp PGNSP PGUID 12 f f t f i 1 701 "701" _null_ dexp - _null_ )); DESCR("exponential"); @@ -2440,6 +2444,8 @@ DATA(insert OID = 1710 ( trunc PGNSP PGUID 14 f f t f i 1 1700 "1700" _null_ DESCR("value truncated to 'scale' of zero"); DATA(insert OID = 1711 ( ceil PGNSP PGUID 12 f f t f i 1 1700 "1700" _null_ numeric_ceil - _null_ )); DESCR("smallest integer >= value"); +DATA(insert OID = 2167 ( ceiling PGNSP PGUID 12 f f t f i 1 1700 "1700" _null_ numeric_ceil - _null_ )); +DESCR("smallest integer >= value"); DATA(insert OID = 1712 ( floor PGNSP PGUID 12 f f t f i 1 1700 "1700" _null_ numeric_floor - _null_ )); DESCR("largest integer <= value"); DATA(insert OID = 1718 ( numeric_eq PGNSP PGUID 12 f f t f i 2 16 "1700 1700" _null_ numeric_eq - _null_ )); @@ -2484,6 +2490,8 @@ DATA(insert OID = 1737 ( numeric_log PGNSP PGUID 12 f f t f i 2 1700 "1700 170 DESCR("logarithm base m of n"); DATA(insert OID = 1738 ( pow PGNSP PGUID 12 f f t f i 2 1700 "1700 1700" _null_ numeric_power - _null_ )); DESCR("m raised to the power of n"); +DATA(insert OID = 2169 ( power PGNSP PGUID 12 f f t f i 2 1700 "1700 1700" _null_ numeric_power - _null_ )); +DESCR("m raised to the power of n"); DATA(insert OID = 1739 ( numeric_power PGNSP PGUID 12 f f t f i 2 1700 "1700 1700" _null_ numeric_power - _null_ )); DESCR("m raised to the power of n"); DATA(insert OID = 1740 ( numeric PGNSP PGUID 12 f f t f i 1 1700 "23" _null_ int4_numeric - _null_ )); diff --git a/src/test/regress/expected/float8-exp-three-digits-win32.out b/src/test/regress/expected/float8-exp-three-digits-win32.out index e64a46399aeb3a9fe15dd2987e8416cdb01537e5..c6f3064b6759fc0b94b7121dea1c77a3ece8b917 100644 --- a/src/test/regress/expected/float8-exp-three-digits-win32.out +++ b/src/test/regress/expected/float8-exp-three-digits-win32.out @@ -225,7 +225,7 @@ SELECT '' AS five, f.f1, f.f1 % AS round_f1 | 1.2345678901234e-200 | 0 (5 rows) --- ceil +-- ceil / ceiling select ceil(f1) as ceil_f1 from float8_tbl f; ceil_f1 ---------------------- @@ -236,6 +236,16 @@ select ceil(f1) as ceil_f1 from float8_tbl f; 1 (5 rows) +select ceiling(f1) as ceiling_f1 from float8_tbl f; + ceiling_f1 +---------------------- + 0 + 1005 + -34 + 1.2345678901234e+200 + 1 +(5 rows) + -- floor select floor(f1) as floor_f1 from float8_tbl f; floor_f1 @@ -281,6 +291,13 @@ SELECT '' AS three, f.f1, |/f.f1 AS sqrt_f1 | 1.2345678901234e-200 | 1.11111110611109e-100 (3 rows) +-- power +SELECT power(float8 '144', float8 '0.5'); + power +------- + 12 +(1 row) + -- take exp of ln(f.f1) SELECT '' AS three, f.f1, exp(ln(f.f1)) AS exp_ln_f1 FROM FLOAT8_TBL f diff --git a/src/test/regress/expected/float8-exp-three-digits.out b/src/test/regress/expected/float8-exp-three-digits.out index 7cfa2bec168db8142c6453819fbcee65d21d8532..479503959bd5112812359c790fcb72546ce79fb3 100644 --- a/src/test/regress/expected/float8-exp-three-digits.out +++ b/src/test/regress/expected/float8-exp-three-digits.out @@ -224,7 +224,7 @@ SELECT '' AS five, f.f1, f.f1 % AS round_f1 | 1.2345678901234e-200 | 0 (5 rows) --- ceil +-- ceil / ceiling select ceil(f1) as ceil_f1 from float8_tbl f; ceil_f1 ---------------------- @@ -235,6 +235,16 @@ select ceil(f1) as ceil_f1 from float8_tbl f; 1 (5 rows) +select ceiling(f1) as ceiling_f1 from float8_tbl f; + ceiling_f1 +---------------------- + 0 + 1005 + -34 + 1.2345678901234e+200 + 1 +(5 rows) + -- floor select floor(f1) as floor_f1 from float8_tbl f; floor_f1 @@ -280,6 +290,13 @@ SELECT '' AS three, f.f1, |/f.f1 AS sqrt_f1 | 1.2345678901234e-200 | 1.11111110611109e-100 (3 rows) +-- power +SELECT power(float8 '144', float8 '0.5'); + power +------- + 12 +(1 row) + -- take exp of ln(f.f1) SELECT '' AS three, f.f1, exp(ln(f.f1)) AS exp_ln_f1 FROM FLOAT8_TBL f diff --git a/src/test/regress/expected/float8-small-is-zero.out b/src/test/regress/expected/float8-small-is-zero.out index 11eefa230b78208623f3da352a6c089ca8724590..b599c1ca5d85dd02c0fb3a68650b2fdaa5396cd5 100644 --- a/src/test/regress/expected/float8-small-is-zero.out +++ b/src/test/regress/expected/float8-small-is-zero.out @@ -233,7 +233,7 @@ SELECT '' AS five, f.f1, f.f1 % AS round_f1 | 1.2345678901234e-200 | 0 (5 rows) --- ceil +-- ceil / ceiling select ceil(f1) as ceil_f1 from float8_tbl f; ceil_f1 ---------------------- @@ -244,6 +244,16 @@ select ceil(f1) as ceil_f1 from float8_tbl f; 1 (5 rows) +select ceiling(f1) as ceiling_f1 from float8_tbl f; + ceiling_f1 +---------------------- + 0 + 1005 + -34 + 1.2345678901234e+200 + 1 +(5 rows) + -- floor select floor(f1) as floor_f1 from float8_tbl f; floor_f1 @@ -289,6 +299,13 @@ SELECT '' AS three, f.f1, |/f.f1 AS sqrt_f1 | 1.2345678901234e-200 | 1.11111110611109e-100 (3 rows) +-- power +SELECT power(float8 '144', float8 '0.5'); + power +------- + 12 +(1 row) + -- take exp of ln(f.f1) SELECT '' AS three, f.f1, exp(ln(f.f1)) AS exp_ln_f1 FROM FLOAT8_TBL f diff --git a/src/test/regress/expected/float8.out b/src/test/regress/expected/float8.out index 03a493aaa4ee1738444ee09bc00f36bdd052fb07..8ba64db0202bc616b4e493e06e6285a87f3bd551 100644 --- a/src/test/regress/expected/float8.out +++ b/src/test/regress/expected/float8.out @@ -225,7 +225,7 @@ SELECT '' AS five, f.f1, f.f1 % AS round_f1 | 1.2345678901234e-200 | 0 (5 rows) --- ceil +-- ceil / ceiling select ceil(f1) as ceil_f1 from float8_tbl f; ceil_f1 ---------------------- @@ -236,6 +236,16 @@ select ceil(f1) as ceil_f1 from float8_tbl f; 1 (5 rows) +select ceiling(f1) as ceiling_f1 from float8_tbl f; + ceiling_f1 +---------------------- + 0 + 1005 + -34 + 1.2345678901234e+200 + 1 +(5 rows) + -- floor select floor(f1) as floor_f1 from float8_tbl f; floor_f1 @@ -281,6 +291,13 @@ SELECT '' AS three, f.f1, |/f.f1 AS sqrt_f1 | 1.2345678901234e-200 | 1.11111110611109e-100 (3 rows) +-- power +SELECT power(float8 '144', float8 '0.5'); + power +------- + 12 +(1 row) + -- take exp of ln(f.f1) SELECT '' AS three, f.f1, exp(ln(f.f1)) AS exp_ln_f1 FROM FLOAT8_TBL f diff --git a/src/test/regress/expected/numeric.out b/src/test/regress/expected/numeric.out index bf3bb441afc24db40e1c0f6f913893e580afd482..6a536c704ba80316fc3fe526fd276da38d8220d9 100644 --- a/src/test/regress/expected/numeric.out +++ b/src/test/regress/expected/numeric.out @@ -646,10 +646,10 @@ SELECT t1.id1, t1.result, t2.expected (0 rows) -- ****************************** --- * POW(10, LN(value)) check +-- * POWER(10, LN(value)) check -- ****************************** DELETE FROM num_result; -INSERT INTO num_result SELECT id, 0, POW(numeric '10', LN(ABS(round(val,200)))) +INSERT INTO num_result SELECT id, 0, POWER(numeric '10', LN(ABS(round(val,200)))) FROM num_data WHERE val != '0.0'; SELECT t1.id1, t1.result, t2.expected @@ -708,6 +708,28 @@ SELECT * FROM fract_only; (6 rows) DROP TABLE fract_only; +-- Simple check that ceil(), floor(), and round() work correctly +CREATE TABLE ceil_floor_round (a numeric); +INSERT INTO ceil_floor_round VALUES ('-5.5'); +INSERT INTO ceil_floor_round VALUES ('-5.499999'); +INSERT INTO ceil_floor_round VALUES ('9.5'); +INSERT INTO ceil_floor_round VALUES ('9.4999999'); +INSERT INTO ceil_floor_round VALUES ('0.0'); +INSERT INTO ceil_floor_round VALUES ('0.0000001'); +INSERT INTO ceil_floor_round VALUES ('-0.000001'); +SELECT a, ceil(a), ceiling(a), floor(a), round(a) FROM ceil_floor_round; + a | ceil | ceiling | floor | round +-----------+------+---------+-------+------- + -5.5 | -5 | -5 | -6 | -6 + -5.499999 | -5 | -5 | -6 | -5 + 9.5 | 10 | 10 | 9 | 10 + 9.4999999 | 10 | 10 | 9 | 9 + 0.0 | 0 | 0 | 0 | 0 + 0.0000001 | 1 | 1 | 0 | 0 + -0.000001 | 0 | 0 | -1 | 0 +(7 rows) + +DROP TABLE ceil_floor_round; -- TO_CHAR() -- SELECT '' AS to_char_1, to_char(val, '9G999G999G999G999G999') diff --git a/src/test/regress/sql/float8.sql b/src/test/regress/sql/float8.sql index 4c706099cdddd9aae6a2dabe20190f83fc6ac8e0..83f0763c6f25fabf8be849a4247489773fe5adec 100644 --- a/src/test/regress/sql/float8.sql +++ b/src/test/regress/sql/float8.sql @@ -85,8 +85,9 @@ SELECT '' AS five, f.f1, %f.f1 AS trunc_f1 SELECT '' AS five, f.f1, f.f1 % AS round_f1 FROM FLOAT8_TBL f; --- ceil +-- ceil / ceiling select ceil(f1) as ceil_f1 from float8_tbl f; +select ceiling(f1) as ceiling_f1 from float8_tbl f; -- floor select floor(f1) as floor_f1 from float8_tbl f; @@ -103,6 +104,9 @@ SELECT '' AS three, f.f1, |/f.f1 AS sqrt_f1 FROM FLOAT8_TBL f WHERE f.f1 > '0.0'; +-- power +SELECT power(float8 '144', float8 '0.5'); + -- take exp of ln(f.f1) SELECT '' AS three, f.f1, exp(ln(f.f1)) AS exp_ln_f1 FROM FLOAT8_TBL f diff --git a/src/test/regress/sql/numeric.sql b/src/test/regress/sql/numeric.sql index b39003440279092782d69947fdc6ff6bc01fb805..59693ab83dc7ba8046b2d418de09000c83b8d766 100644 --- a/src/test/regress/sql/numeric.sql +++ b/src/test/regress/sql/numeric.sql @@ -623,10 +623,10 @@ SELECT t1.id1, t1.result, t2.expected AND t1.result != t2.expected; -- ****************************** --- * POW(10, LN(value)) check +-- * POWER(10, LN(value)) check -- ****************************** DELETE FROM num_result; -INSERT INTO num_result SELECT id, 0, POW(numeric '10', LN(ABS(round(val,200)))) +INSERT INTO num_result SELECT id, 0, POWER(numeric '10', LN(ABS(round(val,200)))) FROM num_data WHERE val != '0.0'; SELECT t1.id1, t1.result, t2.expected @@ -655,6 +655,18 @@ INSERT INTO fract_only VALUES (8, '0.00017'); SELECT * FROM fract_only; DROP TABLE fract_only; +-- Simple check that ceil(), floor(), and round() work correctly +CREATE TABLE ceil_floor_round (a numeric); +INSERT INTO ceil_floor_round VALUES ('-5.5'); +INSERT INTO ceil_floor_round VALUES ('-5.499999'); +INSERT INTO ceil_floor_round VALUES ('9.5'); +INSERT INTO ceil_floor_round VALUES ('9.4999999'); +INSERT INTO ceil_floor_round VALUES ('0.0'); +INSERT INTO ceil_floor_round VALUES ('0.0000001'); +INSERT INTO ceil_floor_round VALUES ('-0.000001'); +SELECT a, ceil(a), ceiling(a), floor(a), round(a) FROM ceil_floor_round; +DROP TABLE ceil_floor_round; + -- TO_CHAR() -- SELECT '' AS to_char_1, to_char(val, '9G999G999G999G999G999')