mirror of
https://github.com/postgres/postgres.git
synced 2025-06-11 20:28:21 +03:00
Add COLLATION FOR expression
reviewed by Jaime Casanova
This commit is contained in:
@ -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