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

Commitfc7fd50

Browse files
author
Neil Conway
committed
Add ceiling() as an alias for ceil(), and power() as an alias for pow().
Regression tests and documentation have both been updated.SQL2003 requires that both ceiling() and ceil() be present, so I havedocumented both spellings. SQL2003 doesn't mention pow() as far as Ican see, so I decided to replace pow() with power() in the documentation:there is little reason to encourage the continued usage of a functionthat isn't compliant with the standard, given a standard-compliantalternative.RELEASE NOTES: should state that pow() is considered deprecated(although I don't see the need to ever remove it.)
1 parent7a66015 commitfc7fd50

File tree

10 files changed

+139
-17
lines changed

10 files changed

+139
-17
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.197 2004/04/10 18:02:59 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.198 2004/04/23 20:32:19 neilc Exp $
33
PostgreSQL documentation
44
-->
55

@@ -587,6 +587,14 @@ PostgreSQL documentation
587587
<entry><literal>-42</literal></entry>
588588
</row>
589589

590+
<row>
591+
<entry><literal><function>ceiling</function>(<type>dp</type> or <type>numeric</type>)</literal></entry>
592+
<entry>(same as input)</entry>
593+
<entry>smallest integer not less than argument (alias for <function>ceil</function>)</entry>
594+
<entry><literal>ceiling(-95.3)</literal></entry>
595+
<entry><literal>-95</literal></entry>
596+
</row>
597+
590598
<row>
591599
<entry><literal><function>degrees</function>(<type>dp</type>)</literal></entry>
592600
<entry><type>dp</type></entry>
@@ -654,20 +662,20 @@ PostgreSQL documentation
654662
</row>
655663

656664
<row>
657-
<entry><literal><function>pow</function>(<parameter>a</parameter> <type>dp</type>,
665+
<entry><literal><function>power</function>(<parameter>a</parameter> <type>dp</type>,
658666
<parameter>b</parameter> <type>dp</type>)</literal></entry>
659667
<entry><type>dp</type></entry>
660668
<entry><parameter>a</> raised to the power of <parameter>b</parameter></entry>
661-
<entry><literal>pow(9.0, 3.0)</literal></entry>
669+
<entry><literal>power(9.0, 3.0)</literal></entry>
662670
<entry><literal>729</literal></entry>
663671
</row>
664672

665673
<row>
666-
<entry><literal><function>pow</function>(<parameter>a</parameter> <type>numeric</type>,
674+
<entry><literal><function>power</function>(<parameter>a</parameter> <type>numeric</type>,
667675
<parameter>b</parameter> <type>numeric</type>)</literal></entry>
668676
<entry><type>numeric</type></entry>
669677
<entry><parameter>a</> raised to the power of <parameter>b</parameter></entry>
670-
<entry><literal>pow(9.0, 3.0)</literal></entry>
678+
<entry><literal>power(9.0, 3.0)</literal></entry>
671679
<entry><literal>729</literal></entry>
672680
</row>
673681

‎src/include/catalog/catversion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.223 2004/04/01 21:28:45 tgl Exp $
40+
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.224 2004/04/23 20:32:19 neilc Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO200403291
56+
#defineCATALOG_VERSION_NO200404220
5757

5858
#endif

‎src/include/catalog/pg_proc.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.324 2004/04/02 23:14:08 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.325 2004/04/23 20:32:19 neilc Exp $
1111
*
1212
* NOTES
1313
* 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_
471471
DESCR("truncate to integer");
472472
DATA(insertOID=2308 (ceilPGNSPPGUID12fftfi1701"701"_null_dceil-_null_ ));
473473
DESCR("smallest integer >= value");
474+
DATA(insertOID=2320 (ceilingPGNSPPGUID12fftfi1701"701"_null_dceil-_null_ ));
475+
DESCR("smallest integer >= value");
474476
DATA(insertOID=2309 (floorPGNSPPGUID12fftfi1701"701"_null_dfloor-_null_ ));
475477
DESCR("largest integer <= value");
476478
DATA(insertOID=2310 (signPGNSPPGUID12fftfi1701"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_
16671669
DESCR("cube root");
16681670
DATA(insertOID=1346 (powPGNSPPGUID12fftfi2701"701 701"_null_dpow-_null_ ));
16691671
DESCR("exponentiation");
1672+
DATA(insertOID=1368 (powerPGNSPPGUID12fftfi2701"701 701"_null_dpow-_null_ ));
1673+
DESCR("exponentiation");
16701674
DATA(insertOID=1347 (expPGNSPPGUID12fftfi1701"701"_null_dexp-_null_ ));
16711675
DESCR("exponential");
16721676

@@ -2440,6 +2444,8 @@ DATA(insert OID = 1710 ( truncPGNSP PGUID 14 f f t f i 1 1700 "1700" _null_
24402444
DESCR("value truncated to 'scale' of zero");
24412445
DATA(insertOID=1711 (ceilPGNSPPGUID12fftfi11700"1700"_null_numeric_ceil-_null_ ));
24422446
DESCR("smallest integer >= value");
2447+
DATA(insertOID=2167 (ceilingPGNSPPGUID12fftfi11700"1700"_null_numeric_ceil-_null_ ));
2448+
DESCR("smallest integer >= value");
24432449
DATA(insertOID=1712 (floorPGNSPPGUID12fftfi11700"1700"_null_numeric_floor-_null_ ));
24442450
DESCR("largest integer <= value");
24452451
DATA(insertOID=1718 (numeric_eqPGNSPPGUID12fftfi216"1700 1700"_null_numeric_eq-_null_ ));
@@ -2484,6 +2490,8 @@ DATA(insert OID = 1737 ( numeric_logPGNSP PGUID 12 f f t f i 2 1700 "1700 170
24842490
DESCR("logarithm base m of n");
24852491
DATA(insertOID=1738 (powPGNSPPGUID12fftfi21700"1700 1700"_null_numeric_power-_null_ ));
24862492
DESCR("m raised to the power of n");
2493+
DATA(insertOID=2169 (powerPGNSPPGUID12fftfi21700"1700 1700"_null_numeric_power-_null_ ));
2494+
DESCR("m raised to the power of n");
24872495
DATA(insertOID=1739 (numeric_powerPGNSPPGUID12fftfi21700"1700 1700"_null_numeric_power-_null_ ));
24882496
DESCR("m raised to the power of n");
24892497
DATA(insertOID=1740 (numericPGNSPPGUID12fftfi11700"23"_null_int4_numeric-_null_ ));

‎src/test/regress/expected/float8-exp-three-digits-win32.out

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ SELECT '' AS five, f.f1, f.f1 % AS round_f1
225225
| 1.2345678901234e-200 | 0
226226
(5 rows)
227227

228-
-- ceil
228+
-- ceil / ceiling
229229
select ceil(f1) as ceil_f1 from float8_tbl f;
230230
ceil_f1
231231
----------------------
@@ -236,6 +236,16 @@ select ceil(f1) as ceil_f1 from float8_tbl f;
236236
1
237237
(5 rows)
238238

239+
select ceiling(f1) as ceiling_f1 from float8_tbl f;
240+
ceiling_f1
241+
----------------------
242+
0
243+
1005
244+
-34
245+
1.2345678901234e+200
246+
1
247+
(5 rows)
248+
239249
-- floor
240250
select floor(f1) as floor_f1 from float8_tbl f;
241251
floor_f1
@@ -281,6 +291,13 @@ SELECT '' AS three, f.f1, |/f.f1 AS sqrt_f1
281291
| 1.2345678901234e-200 | 1.11111110611109e-100
282292
(3 rows)
283293

294+
-- power
295+
SELECT power(float8 '144', float8 '0.5');
296+
power
297+
-------
298+
12
299+
(1 row)
300+
284301
-- take exp of ln(f.f1)
285302
SELECT '' AS three, f.f1, exp(ln(f.f1)) AS exp_ln_f1
286303
FROM FLOAT8_TBL f

‎src/test/regress/expected/float8-exp-three-digits.out

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ SELECT '' AS five, f.f1, f.f1 % AS round_f1
224224
| 1.2345678901234e-200 | 0
225225
(5 rows)
226226

227-
-- ceil
227+
-- ceil / ceiling
228228
select ceil(f1) as ceil_f1 from float8_tbl f;
229229
ceil_f1
230230
----------------------
@@ -235,6 +235,16 @@ select ceil(f1) as ceil_f1 from float8_tbl f;
235235
1
236236
(5 rows)
237237

238+
select ceiling(f1) as ceiling_f1 from float8_tbl f;
239+
ceiling_f1
240+
----------------------
241+
0
242+
1005
243+
-34
244+
1.2345678901234e+200
245+
1
246+
(5 rows)
247+
238248
-- floor
239249
select floor(f1) as floor_f1 from float8_tbl f;
240250
floor_f1
@@ -280,6 +290,13 @@ SELECT '' AS three, f.f1, |/f.f1 AS sqrt_f1
280290
| 1.2345678901234e-200 | 1.11111110611109e-100
281291
(3 rows)
282292

293+
-- power
294+
SELECT power(float8 '144', float8 '0.5');
295+
power
296+
-------
297+
12
298+
(1 row)
299+
283300
-- take exp of ln(f.f1)
284301
SELECT '' AS three, f.f1, exp(ln(f.f1)) AS exp_ln_f1
285302
FROM FLOAT8_TBL f

‎src/test/regress/expected/float8-small-is-zero.out

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ SELECT '' AS five, f.f1, f.f1 % AS round_f1
233233
| 1.2345678901234e-200 | 0
234234
(5 rows)
235235

236-
-- ceil
236+
-- ceil / ceiling
237237
select ceil(f1) as ceil_f1 from float8_tbl f;
238238
ceil_f1
239239
----------------------
@@ -244,6 +244,16 @@ select ceil(f1) as ceil_f1 from float8_tbl f;
244244
1
245245
(5 rows)
246246

247+
select ceiling(f1) as ceiling_f1 from float8_tbl f;
248+
ceiling_f1
249+
----------------------
250+
0
251+
1005
252+
-34
253+
1.2345678901234e+200
254+
1
255+
(5 rows)
256+
247257
-- floor
248258
select floor(f1) as floor_f1 from float8_tbl f;
249259
floor_f1
@@ -289,6 +299,13 @@ SELECT '' AS three, f.f1, |/f.f1 AS sqrt_f1
289299
| 1.2345678901234e-200 | 1.11111110611109e-100
290300
(3 rows)
291301

302+
-- power
303+
SELECT power(float8 '144', float8 '0.5');
304+
power
305+
-------
306+
12
307+
(1 row)
308+
292309
-- take exp of ln(f.f1)
293310
SELECT '' AS three, f.f1, exp(ln(f.f1)) AS exp_ln_f1
294311
FROM FLOAT8_TBL f

‎src/test/regress/expected/float8.out

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ SELECT '' AS five, f.f1, f.f1 % AS round_f1
225225
| 1.2345678901234e-200 | 0
226226
(5 rows)
227227

228-
-- ceil
228+
-- ceil / ceiling
229229
select ceil(f1) as ceil_f1 from float8_tbl f;
230230
ceil_f1
231231
----------------------
@@ -236,6 +236,16 @@ select ceil(f1) as ceil_f1 from float8_tbl f;
236236
1
237237
(5 rows)
238238

239+
select ceiling(f1) as ceiling_f1 from float8_tbl f;
240+
ceiling_f1
241+
----------------------
242+
0
243+
1005
244+
-34
245+
1.2345678901234e+200
246+
1
247+
(5 rows)
248+
239249
-- floor
240250
select floor(f1) as floor_f1 from float8_tbl f;
241251
floor_f1
@@ -281,6 +291,13 @@ SELECT '' AS three, f.f1, |/f.f1 AS sqrt_f1
281291
| 1.2345678901234e-200 | 1.11111110611109e-100
282292
(3 rows)
283293

294+
-- power
295+
SELECT power(float8 '144', float8 '0.5');
296+
power
297+
-------
298+
12
299+
(1 row)
300+
284301
-- take exp of ln(f.f1)
285302
SELECT '' AS three, f.f1, exp(ln(f.f1)) AS exp_ln_f1
286303
FROM FLOAT8_TBL f

‎src/test/regress/expected/numeric.out

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,10 +646,10 @@ SELECT t1.id1, t1.result, t2.expected
646646
(0 rows)
647647

648648
-- ******************************
649-
-- *POW(10, LN(value)) check
649+
-- *POWER(10, LN(value)) check
650650
-- ******************************
651651
DELETE FROM num_result;
652-
INSERT INTO num_result SELECT id, 0,POW(numeric '10', LN(ABS(round(val,200))))
652+
INSERT INTO num_result SELECT id, 0,POWER(numeric '10', LN(ABS(round(val,200))))
653653
FROM num_data
654654
WHERE val != '0.0';
655655
SELECT t1.id1, t1.result, t2.expected
@@ -708,6 +708,28 @@ SELECT * FROM fract_only;
708708
(6 rows)
709709

710710
DROP TABLE fract_only;
711+
-- Simple check that ceil(), floor(), and round() work correctly
712+
CREATE TABLE ceil_floor_round (a numeric);
713+
INSERT INTO ceil_floor_round VALUES ('-5.5');
714+
INSERT INTO ceil_floor_round VALUES ('-5.499999');
715+
INSERT INTO ceil_floor_round VALUES ('9.5');
716+
INSERT INTO ceil_floor_round VALUES ('9.4999999');
717+
INSERT INTO ceil_floor_round VALUES ('0.0');
718+
INSERT INTO ceil_floor_round VALUES ('0.0000001');
719+
INSERT INTO ceil_floor_round VALUES ('-0.000001');
720+
SELECT a, ceil(a), ceiling(a), floor(a), round(a) FROM ceil_floor_round;
721+
a | ceil | ceiling | floor | round
722+
-----------+------+---------+-------+-------
723+
-5.5 | -5 | -5 | -6 | -6
724+
-5.499999 | -5 | -5 | -6 | -5
725+
9.5 | 10 | 10 | 9 | 10
726+
9.4999999 | 10 | 10 | 9 | 9
727+
0.0 | 0 | 0 | 0 | 0
728+
0.0000001 | 1 | 1 | 0 | 0
729+
-0.000001 | 0 | 0 | -1 | 0
730+
(7 rows)
731+
732+
DROP TABLE ceil_floor_round;
711733
-- TO_CHAR()
712734
--
713735
SELECT '' AS to_char_1, to_char(val, '9G999G999G999G999G999')

‎src/test/regress/sql/float8.sql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ SELECT '' AS five, f.f1, %f.f1 AS trunc_f1
8585
SELECT''AS five,f.f1,f.f1 %AS round_f1
8686
FROM FLOAT8_TBL f;
8787

88-
-- ceil
88+
-- ceil / ceiling
8989
select ceil(f1)as ceil_f1from float8_tbl f;
90+
select ceiling(f1)as ceiling_f1from float8_tbl f;
9091

9192
-- floor
9293
select floor(f1)as floor_f1from float8_tbl f;
@@ -103,6 +104,9 @@ SELECT '' AS three, f.f1, |/f.f1 AS sqrt_f1
103104
FROM FLOAT8_TBL f
104105
WHEREf.f1>'0.0';
105106

107+
-- power
108+
SELECT power(float8'144', float8'0.5');
109+
106110
-- take exp of ln(f.f1)
107111
SELECT''AS three,f.f1, exp(ln(f.f1))AS exp_ln_f1
108112
FROM FLOAT8_TBL f

‎src/test/regress/sql/numeric.sql

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,10 +623,10 @@ SELECT t1.id1, t1.result, t2.expected
623623
ANDt1.result!=t2.expected;
624624

625625
-- ******************************
626-
-- *POW(10, LN(value)) check
626+
-- *POWER(10, LN(value)) check
627627
-- ******************************
628628
DELETEFROM num_result;
629-
INSERT INTO num_resultSELECT id,0,POW(numeric'10', LN(ABS(round(val,200))))
629+
INSERT INTO num_resultSELECT id,0,POWER(numeric'10', LN(ABS(round(val,200))))
630630
FROM num_data
631631
WHERE val!='0.0';
632632
SELECTt1.id1,t1.result,t2.expected
@@ -655,6 +655,18 @@ INSERT INTO fract_only VALUES (8, '0.00017');
655655
SELECT*FROM fract_only;
656656
DROPTABLE fract_only;
657657

658+
-- Simple check that ceil(), floor(), and round() work correctly
659+
CREATETABLEceil_floor_round (anumeric);
660+
INSERT INTO ceil_floor_roundVALUES ('-5.5');
661+
INSERT INTO ceil_floor_roundVALUES ('-5.499999');
662+
INSERT INTO ceil_floor_roundVALUES ('9.5');
663+
INSERT INTO ceil_floor_roundVALUES ('9.4999999');
664+
INSERT INTO ceil_floor_roundVALUES ('0.0');
665+
INSERT INTO ceil_floor_roundVALUES ('0.0000001');
666+
INSERT INTO ceil_floor_roundVALUES ('-0.000001');
667+
SELECT a, ceil(a), ceiling(a), floor(a), round(a)FROM ceil_floor_round;
668+
DROPTABLE ceil_floor_round;
669+
658670
-- TO_CHAR()
659671
--
660672
SELECT''AS to_char_1, to_char(val,'9G999G999G999G999G999')

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp