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
b8fab241
Commit
b8fab241
authored
Nov 03, 2008
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add pg_typeof() function.
Brendan Jurd
parent
06c22d7f
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
100 additions
and
7 deletions
+100
-7
doc/src/sgml/func.sgml
doc/src/sgml/func.sgml
+16
-1
src/backend/utils/adt/misc.c
src/backend/utils/adt/misc.c
+11
-1
src/include/catalog/catversion.h
src/include/catalog/catversion.h
+2
-2
src/include/catalog/pg_proc.h
src/include/catalog/pg_proc.h
+3
-2
src/include/utils/builtins.h
src/include/utils/builtins.h
+2
-1
src/test/regress/expected/polymorphism.out
src/test/regress/expected/polymorphism.out
+55
-0
src/test/regress/sql/polymorphism.sql
src/test/regress/sql/polymorphism.sql
+11
-0
No files found.
doc/src/sgml/func.sgml
View file @
b8fab241
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.45
1 2008/10/27 09:37:46 petere
Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.45
2 2008/11/03 17:51:12 tgl
Exp $ -->
<chapter
id=
"functions"
>
<title>
Functions and Operators
</title>
...
...
@@ -11643,6 +11643,10 @@ SELECT pg_type_is_visible('myschema.widget'::regtype);
<primary>
pg_tablespace_databases
</primary>
</indexterm>
<indexterm>
<primary>
pg_typeof
</primary>
</indexterm>
<para>
<xref
linkend=
"functions-info-catalog-table"
>
lists functions that
extract information from the system catalogs.
...
...
@@ -11766,6 +11770,11 @@ SELECT pg_type_is_visible('myschema.widget'::regtype);
<entry><type>
setof oid
</type></entry>
<entry>
get the set of database OIDs that have objects in the tablespace
</entry>
</row>
<row>
<entry><literal><function>
pg_typeof
</function>
(
<parameter>
any
</parameter>
)
</literal></entry>
<entry><type>
regtype
</type></entry>
<entry>
get the data type of any value
</entry>
</row>
</tbody>
</tgroup>
</table>
...
...
@@ -11848,6 +11857,12 @@ SELECT pg_type_is_visible('myschema.widget'::regtype);
<structname>
pg_class
</>
catalogs.
</para>
<para>
<function>
pg_typeof
</function>
returns the OID of the data type of the
value that is passed to it. This can be helpful for troubleshooting or
dynamically constructing SQL queries.
</para>
<indexterm>
<primary>
col_description
</primary>
</indexterm>
...
...
src/backend/utils/adt/misc.c
View file @
b8fab241
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/misc.c,v 1.6
4 2008/10/05 17:33:16 petere
Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/misc.c,v 1.6
5 2008/11/03 17:51:13 tgl
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -371,3 +371,13 @@ pg_get_keywords(PG_FUNCTION_ARGS)
SRF_RETURN_DONE
(
funcctx
);
}
/*
* Return the type of the argument.
*/
Datum
pg_typeof
(
PG_FUNCTION_ARGS
)
{
PG_RETURN_OID
(
get_fn_expr_argtype
(
fcinfo
->
flinfo
,
0
));
}
src/include/catalog/catversion.h
View file @
b8fab241
...
...
@@ -37,7 +37,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.50
0 2008/10/31 08:39:22 heikki
Exp $
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.50
1 2008/11/03 17:51:13 tgl
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -53,6 +53,6 @@
*/
/* yyyymmddN */
#define CATALOG_VERSION_NO 20081
031
1
#define CATALOG_VERSION_NO 20081
103
1
#endif
src/include/catalog/pg_proc.h
View file @
b8fab241
...
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.52
0 2008/10/14 17:12:3
3 tgl Exp $
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.52
1 2008/11/03 17:51:1
3 tgl Exp $
*
* NOTES
* The script catalog/genbki.sh reads this file and generates .bki
...
...
@@ -2289,7 +2289,8 @@ DESCR("result type of a function");
DATA
(
insert
OID
=
1686
(
pg_get_keywords
PGNSP
PGUID
12
10
400
0
f
f
t
t
s
0
2249
""
"{25,18,25}"
"{o,o,o}"
"{word,catcode,catdesc}"
pg_get_keywords
_null_
_null_
_null_
));
DESCR
(
"list of SQL keywords"
);
DATA
(
insert
OID
=
1619
(
pg_typeof
PGNSP
PGUID
12
1
0
0
f
f
f
f
i
1
2206
"2276"
_null_
_null_
_null_
pg_typeof
_null_
_null_
_null_
));
DESCR
(
"returns the type of the argument"
);
/* Generic referential integrity constraint triggers */
DATA
(
insert
OID
=
1644
(
RI_FKey_check_ins
PGNSP
PGUID
12
1
0
0
f
f
t
f
v
0
2279
""
_null_
_null_
_null_
RI_FKey_check_ins
_null_
_null_
_null_
));
...
...
src/include/utils/builtins.h
View file @
b8fab241
...
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.32
4 2008/10/13 16:25:20
tgl Exp $
* $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.32
5 2008/11/03 17:51:13
tgl Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -404,6 +404,7 @@ extern Datum pg_tablespace_databases(PG_FUNCTION_ARGS);
extern
Datum
pg_rotate_logfile
(
PG_FUNCTION_ARGS
);
extern
Datum
pg_sleep
(
PG_FUNCTION_ARGS
);
extern
Datum
pg_get_keywords
(
PG_FUNCTION_ARGS
);
extern
Datum
pg_typeof
(
PG_FUNCTION_ARGS
);
/* oid.c */
extern
Datum
oidin
(
PG_FUNCTION_ARGS
);
...
...
src/test/regress/expected/polymorphism.out
View file @
b8fab241
...
...
@@ -721,3 +721,58 @@ LINE 1: select formarray(1, variadic array['x'::text]);
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
drop function formarray(anyelement, variadic anyarray);
-- test pg_typeof() function
select pg_typeof(null); -- unknown
pg_typeof
-----------
unknown
(1 row)
select pg_typeof(0); -- integer
pg_typeof
-----------
integer
(1 row)
select pg_typeof(0.0); -- numeric
pg_typeof
-----------
numeric
(1 row)
select pg_typeof(1+1 = 2); -- boolean
pg_typeof
-----------
boolean
(1 row)
select pg_typeof('x'); -- unknown
pg_typeof
-----------
unknown
(1 row)
select pg_typeof('' || ''); -- text
pg_typeof
-----------
text
(1 row)
select pg_typeof(pg_typeof(0)); -- regtype
pg_typeof
-----------
regtype
(1 row)
select pg_typeof(array[1.2,55.5]); -- numeric[]
pg_typeof
-----------
numeric[]
(1 row)
select pg_typeof(myleast(10, 1, 20, 33)); -- polymorphic input
pg_typeof
-----------
integer
(1 row)
src/test/regress/sql/polymorphism.sql
View file @
b8fab241
...
...
@@ -469,3 +469,14 @@ select formarray(1, 'x'::text); -- fail, type mismatch
select
formarray
(
1
,
variadic
array
[
'x'
::
text
]);
-- fail, type mismatch
drop
function
formarray
(
anyelement
,
variadic
anyarray
);
-- test pg_typeof() function
select
pg_typeof
(
null
);
-- unknown
select
pg_typeof
(
0
);
-- integer
select
pg_typeof
(
0
.
0
);
-- numeric
select
pg_typeof
(
1
+
1
=
2
);
-- boolean
select
pg_typeof
(
'x'
);
-- unknown
select
pg_typeof
(
''
||
''
);
-- text
select
pg_typeof
(
pg_typeof
(
0
));
-- regtype
select
pg_typeof
(
array
[
1
.
2
,
55
.
5
]);
-- numeric[]
select
pg_typeof
(
myleast
(
10
,
1
,
20
,
33
));
-- polymorphic input
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