diff options
author | Peter Eisentraut <peter_e@gmx.net> | 2012-03-02 21:12:16 +0200 |
---|---|---|
committer | Peter Eisentraut <peter_e@gmx.net> | 2012-03-02 21:12:16 +0200 |
commit | 6688d2878e516314418274ee95c5c30412351933 (patch) | |
tree | d3f3048615781ca3a793a452482f774e8f9f301c /src/backend/utils/adt/misc.c | |
parent | d41f510c807ce8b12c572196e2ae8f3817ac253a (diff) |
Add COLLATION FOR expression
reviewed by Jaime Casanova
Diffstat (limited to 'src/backend/utils/adt/misc.c')
-rw-r--r-- | src/backend/utils/adt/misc.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c index 3de6a5c9923..6a1b4771472 100644 --- a/src/backend/utils/adt/misc.c +++ b/src/backend/utils/adt/misc.c @@ -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))); +} |