mirror of
https://github.com/postgres/postgres.git
synced 2025-11-07 19:06:32 +03:00
Add COLLATION FOR expression
reviewed by Jaime Casanova
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user