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
6688d287
Commit
6688d287
authored
Mar 02, 2012
by
Peter Eisentraut
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add COLLATION FOR expression
reviewed by Jaime Casanova
parent
d41f510c
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
103 additions
and
3 deletions
+103
-3
doc/src/sgml/func.sgml
doc/src/sgml/func.sgml
+30
-0
src/backend/parser/gram.y
src/backend/parser/gram.y
+14
-1
src/backend/utils/adt/misc.c
src/backend/utils/adt/misc.c
+27
-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/parser/kwlist.h
src/include/parser/kwlist.h
+1
-1
src/include/utils/builtins.h
src/include/utils/builtins.h
+1
-0
src/test/regress/expected/collate.out
src/test/regress/expected/collate.out
+20
-0
src/test/regress/sql/collate.sql
src/test/regress/sql/collate.sql
+7
-0
No files found.
doc/src/sgml/func.sgml
View file @
6688d287
...
...
@@ -13698,6 +13698,10 @@ SELECT pg_type_is_visible('myschema.widget'::regtype);
<primary>
pg_typeof
</primary>
</indexterm>
<indexterm>
<primary>
collation for
</primary>
</indexterm>
<para>
<xref
linkend=
"functions-info-catalog-table"
>
lists functions that
extract information from the system catalogs.
...
...
@@ -13859,6 +13863,11 @@ SELECT pg_type_is_visible('myschema.widget'::regtype);
<entry><type>
regtype
</type></entry>
<entry>
get the data type of any value
</entry>
</row>
<row>
<entry><literal><function>
collation for (
<parameter>
any
</parameter>
)
</function></literal></entry>
<entry><type>
text
</type></entry>
<entry>
get the collation of the argument
</entry>
</row>
</tbody>
</tgroup>
</table>
...
...
@@ -13983,6 +13992,27 @@ SELECT typlen FROM pg_type WHERE oid = pg_typeof(33);
4
(1 row)
</programlisting>
</para>
<para>
The expression
<literal>
collation for
</literal>
returns the collation of the
value that is passed to it. Example:
<programlisting>
SELECT collation for (description) FROM pg_description LIMIT 1;
pg_collation_for
------------------
"default"
(1 row)
SELECT collation for ('foo' COLLATE "de_DE");
pg_collation_for
------------------
"de_DE"
(1 row)
</programlisting>
The value might be quoted and schema-qualified. If no collation is derived
for the argument expression, then a null value is returned. If the argument
is not of a collatable data type, then an error is raised.
</para>
<indexterm>
...
...
src/backend/parser/gram.y
View file @
6688d287
...
...
@@ -10701,6 +10701,19 @@ func_expr: func_name '(' ')' over_clause
n->location = @1;
$$ = (Node *)n;
}
| COLLATION FOR '(' a_expr ')'
{
FuncCall *n = makeNode(FuncCall);
n->funcname = SystemFuncName("pg_collation_for");
n->args = list_make1($4);
n->agg_order = NIL;
n->agg_star = FALSE;
n->agg_distinct = FALSE;
n->func_variadic = FALSE;
n->over = NULL;
n->location = @1;
$$ = (Node *)n;
}
| CURRENT_DATE
{
/*
...
...
@@ -12152,7 +12165,6 @@ unreserved_keyword:
| CLASS
| CLOSE
| CLUSTER
| COLLATION
| COMMENT
| COMMENTS
| COMMIT
...
...
@@ -12491,6 +12503,7 @@ reserved_keyword:
| CAST
| CHECK
| COLLATE
| COLLATION
| COLUMN
| CONSTRAINT
| CREATE
...
...
src/backend/utils/adt/misc.c
View file @
6688d287
...
...
@@ -32,6 +32,7 @@
#include "storage/pmsignal.h"
#include "storage/proc.h"
#include "storage/procarray.h"
#include "utils/lsyscache.h"
#include "tcop/tcopprot.h"
#include "utils/builtins.h"
#include "utils/timestamp.h"
...
...
@@ -492,3 +493,29 @@ pg_typeof(PG_FUNCTION_ARGS)
{
PG_RETURN_OID
(
get_fn_expr_argtype
(
fcinfo
->
flinfo
,
0
));
}
/*
* Implementation of the COLLATE FOR expression; returns the collation
* of the argument.
*/
Datum
pg_collation_for
(
PG_FUNCTION_ARGS
)
{
Oid
typeid
;
Oid
collid
;
typeid
=
get_fn_expr_argtype
(
fcinfo
->
flinfo
,
0
);
if
(
!
typeid
)
PG_RETURN_NULL
();
if
(
!
type_is_collatable
(
typeid
)
&&
typeid
!=
UNKNOWNOID
)
ereport
(
ERROR
,
(
errcode
(
ERRCODE_DATATYPE_MISMATCH
),
errmsg
(
"collations are not supported by type %s"
,
format_type_be
(
typeid
))));
collid
=
PG_GET_COLLATION
();
if
(
!
collid
)
PG_RETURN_NULL
();
PG_RETURN_TEXT_P
(
cstring_to_text
(
generate_collation_name
(
collid
)));
}
src/include/catalog/catversion.h
View file @
6688d287
...
...
@@ -53,6 +53,6 @@
*/
/* yyyymmddN */
#define CATALOG_VERSION_NO 2012030
1
1
#define CATALOG_VERSION_NO 2012030
2
1
#endif
src/include/catalog/pg_proc.h
View file @
6688d287
...
...
@@ -1953,6 +1953,8 @@ DESCR("convert generic options array to name/value table");
DATA
(
insert
OID
=
1619
(
pg_typeof
PGNSP
PGUID
12
1
0
0
0
f
f
f
f
f
f
s
1
0
2206
"2276"
_null_
_null_
_null_
_null_
pg_typeof
_null_
_null_
_null_
));
DESCR
(
"type of the argument"
);
DATA
(
insert
OID
=
3162
(
pg_collation_for
PGNSP
PGUID
12
1
0
0
0
f
f
f
f
f
f
s
1
0
25
"2276"
_null_
_null_
_null_
_null_
pg_collation_for
_null_
_null_
_null_
));
DESCR
(
"collation of the argument; implementation of the COLLATION FOR expression"
);
/* Deferrable unique constraint trigger */
DATA
(
insert
OID
=
1250
(
unique_key_recheck
PGNSP
PGUID
12
1
0
0
0
f
f
f
f
t
f
v
0
0
2279
""
_null_
_null_
_null_
_null_
unique_key_recheck
_null_
_null_
_null_
));
...
...
src/include/parser/kwlist.h
View file @
6688d287
...
...
@@ -79,7 +79,7 @@ PG_KEYWORD("close", CLOSE, UNRESERVED_KEYWORD)
PG_KEYWORD
(
"cluster"
,
CLUSTER
,
UNRESERVED_KEYWORD
)
PG_KEYWORD
(
"coalesce"
,
COALESCE
,
COL_NAME_KEYWORD
)
PG_KEYWORD
(
"collate"
,
COLLATE
,
RESERVED_KEYWORD
)
PG_KEYWORD
(
"collation"
,
COLLATION
,
UN
RESERVED_KEYWORD
)
PG_KEYWORD
(
"collation"
,
COLLATION
,
RESERVED_KEYWORD
)
PG_KEYWORD
(
"column"
,
COLUMN
,
RESERVED_KEYWORD
)
PG_KEYWORD
(
"comment"
,
COMMENT
,
UNRESERVED_KEYWORD
)
PG_KEYWORD
(
"comments"
,
COMMENTS
,
UNRESERVED_KEYWORD
)
...
...
src/include/utils/builtins.h
View file @
6688d287
...
...
@@ -480,6 +480,7 @@ 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
);
extern
Datum
pg_collation_for
(
PG_FUNCTION_ARGS
);
/* oid.c */
extern
Datum
oidin
(
PG_FUNCTION_ARGS
);
...
...
src/test/regress/expected/collate.out
View file @
6688d287
...
...
@@ -577,6 +577,26 @@ RESET enable_nestloop;
-- 9.1 bug with useless COLLATE in an expression subject to length coercion
CREATE TEMP TABLE vctable (f1 varchar(25));
INSERT INTO vctable VALUES ('foo' COLLATE "C");
SELECT collation for ('foo'); -- unknown type - null
pg_collation_for
------------------
(1 row)
SELECT collation for ('foo'::text);
pg_collation_for
------------------
"default"
(1 row)
SELECT collation for ((SELECT a FROM collate_test1 LIMIT 1)); -- non-collatable type - error
ERROR: collations are not supported by type integer
SELECT collation for ((SELECT b FROM collate_test1 LIMIT 1));
pg_collation_for
------------------
"C"
(1 row)
--
-- Clean up. Many of these table names will be re-used if the user is
-- trying to run any platform-specific collation tests later, so we
...
...
src/test/regress/sql/collate.sql
View file @
6688d287
...
...
@@ -219,6 +219,13 @@ RESET enable_nestloop;
CREATE
TEMP
TABLE
vctable
(
f1
varchar
(
25
));
INSERT
INTO
vctable
VALUES
(
'foo'
COLLATE
"C"
);
SELECT
collation
for
(
'foo'
);
-- unknown type - null
SELECT
collation
for
(
'foo'
::
text
);
SELECT
collation
for
((
SELECT
a
FROM
collate_test1
LIMIT
1
));
-- non-collatable type - error
SELECT
collation
for
((
SELECT
b
FROM
collate_test1
LIMIT
1
));
--
-- Clean up. Many of these table names will be re-used if the user is
-- trying to run any platform-specific collation tests later, so we
...
...
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