Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
abb17339
Commit
abb17339
authored
Jan 05, 2016
by
Alvaro Herrera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add scale(numeric)
Author: Marko Tiikkaja
parent
419400c5
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
105 additions
and
1 deletion
+105
-1
doc/src/sgml/func.sgml
doc/src/sgml/func.sgml
+13
-0
src/backend/utils/adt/numeric.c
src/backend/utils/adt/numeric.c
+17
-0
src/include/catalog/catversion.h
src/include/catalog/catversion.h
+1
-1
src/include/catalog/pg_proc.h
src/include/catalog/pg_proc.h
+2
-0
src/include/utils/builtins.h
src/include/utils/builtins.h
+1
-0
src/test/regress/expected/numeric.out
src/test/regress/expected/numeric.out
+57
-0
src/test/regress/sql/numeric.sql
src/test/regress/sql/numeric.sql
+14
-0
No files found.
doc/src/sgml/func.sgml
View file @
abb17339
...
...
@@ -849,6 +849,19 @@
<entry><literal>
42.44
</literal></entry>
</row>
<row>
<entry>
<indexterm>
<primary>
scale
</primary>
</indexterm>
<literal><function>
scale(
<type>
numeric
</type>
)
</function></literal>
</entry>
<entry><type>
numeric
</type></entry>
<entry>
scale of the argument (the number of decimal digits in the fractional part)
</entry>
<entry><literal>
scale(8.41)
</literal></entry>
<entry><literal>
2
</literal></entry>
</row>
<row>
<entry>
<indexterm>
...
...
src/backend/utils/adt/numeric.c
View file @
abb17339
...
...
@@ -2825,6 +2825,23 @@ numeric_power(PG_FUNCTION_ARGS)
PG_RETURN_NUMERIC
(
res
);
}
/*
* numeric_scale() -
*
* Returns the scale, i.e. the count of decimal digits in the fractional part
*/
Datum
numeric_scale
(
PG_FUNCTION_ARGS
)
{
Numeric
num
=
PG_GETARG_NUMERIC
(
0
);
if
(
NUMERIC_IS_NAN
(
num
))
PG_RETURN_NULL
();
PG_RETURN_INT32
(
NUMERIC_DSCALE
(
num
));
}
/* ----------------------------------------------------------------------
*
...
...
src/include/catalog/catversion.h
View file @
abb17339
...
...
@@ -53,6 +53,6 @@
*/
/* yyyymmddN */
#define CATALOG_VERSION_NO 20160105
1
#define CATALOG_VERSION_NO 20160105
2
#endif
src/include/catalog/pg_proc.h
View file @
abb17339
...
...
@@ -2361,6 +2361,8 @@ DESCR("exponentiation");
DATA
(
insert
OID
=
2169
(
power
PGNSP
PGUID
12
1
0
0
0
f
f
f
f
t
f
i
s
2
0
1700
"1700 1700"
_null_
_null_
_null_
_null_
_null_
numeric_power
_null_
_null_
_null_
));
DESCR
(
"exponentiation"
);
DATA
(
insert
OID
=
1739
(
numeric_power
PGNSP
PGUID
12
1
0
0
0
f
f
f
f
t
f
i
s
2
0
1700
"1700 1700"
_null_
_null_
_null_
_null_
_null_
numeric_power
_null_
_null_
_null_
));
DATA
(
insert
OID
=
8888
(
scale
PGNSP
PGUID
12
1
0
0
0
f
f
f
f
t
f
i
s
1
0
23
"1700"
_null_
_null_
_null_
_null_
_null_
numeric_scale
_null_
_null_
_null_
));
DESCR
(
"number of decimal digits in the fractional part"
);
DATA
(
insert
OID
=
1740
(
numeric
PGNSP
PGUID
12
1
0
0
0
f
f
f
f
t
f
i
s
1
0
1700
"23"
_null_
_null_
_null_
_null_
_null_
int4_numeric
_null_
_null_
_null_
));
DESCR
(
"convert int4 to numeric"
);
DATA
(
insert
OID
=
1741
(
log
PGNSP
PGUID
14
1
0
0
0
f
f
f
f
t
f
i
s
1
0
1700
"1700"
_null_
_null_
_null_
_null_
_null_
"select pg_catalog.log(10, $1)"
_null_
_null_
_null_
));
...
...
src/include/utils/builtins.h
View file @
abb17339
...
...
@@ -1022,6 +1022,7 @@ extern Datum numeric_exp(PG_FUNCTION_ARGS);
extern
Datum
numeric_ln
(
PG_FUNCTION_ARGS
);
extern
Datum
numeric_log
(
PG_FUNCTION_ARGS
);
extern
Datum
numeric_power
(
PG_FUNCTION_ARGS
);
extern
Datum
numeric_scale
(
PG_FUNCTION_ARGS
);
extern
Datum
int4_numeric
(
PG_FUNCTION_ARGS
);
extern
Datum
numeric_int4
(
PG_FUNCTION_ARGS
);
extern
Datum
int8_numeric
(
PG_FUNCTION_ARGS
);
...
...
src/test/regress/expected/numeric.out
View file @
abb17339
...
...
@@ -1852,3 +1852,60 @@ select log(3.1954752e47, 9.4792021e-73);
-1.51613372350688302142917386143459361608600157692779164475351842333265418126982165
(1 row)
--
-- Tests for scale()
--
select scale(numeric 'NaN');
scale
-------
(1 row)
select scale(NULL::numeric);
scale
-------
(1 row)
select scale(1.12);
scale
-------
2
(1 row)
select scale(0);
scale
-------
0
(1 row)
select scale(0.00);
scale
-------
2
(1 row)
select scale(1.12345);
scale
-------
5
(1 row)
select scale(110123.12475871856128);
scale
-------
14
(1 row)
select scale(-1123.12471856128);
scale
-------
11
(1 row)
select scale(-13.000000000000000);
scale
-------
15
(1 row)
src/test/regress/sql/numeric.sql
View file @
abb17339
...
...
@@ -983,3 +983,17 @@ select log(1.23e-89, 6.4689e45);
select
log
(
0
.
99923
,
4
.
58934
e34
);
select
log
(
1
.
000016
,
8
.
452010
e18
);
select
log
(
3
.
1954752
e47
,
9
.
4792021
e
-
73
);
--
-- Tests for scale()
--
select
scale
(
numeric
'NaN'
);
select
scale
(
NULL
::
numeric
);
select
scale
(
1
.
12
);
select
scale
(
0
);
select
scale
(
0
.
00
);
select
scale
(
1
.
12345
);
select
scale
(
110123
.
12475871856128
);
select
scale
(
-
1123
.
12471856128
);
select
scale
(
-
13
.
000000000000000
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment