Revision 13134
Added by Aaron Marcuse-Kubitza over 10 years ago
trunk/schemas/util.sql | ||
---|---|---|
693 | 693 |
|
694 | 694 |
|
695 | 695 |
-- |
696 |
-- Name: cast(text, anyelement); Type: FUNCTION; Schema: util; Owner: - |
|
697 |
-- |
|
698 |
|
|
699 |
CREATE FUNCTION "cast"(value text, ret_type_null anyelement) RETURNS anyelement |
|
700 |
LANGUAGE plpgsql IMMUTABLE |
|
701 |
AS $$ |
|
702 |
/* must use LANGUAGE plpgsql because LANGUAGE sql does not assignment-cast the |
|
703 |
return value, causing a type mismatch */ |
|
704 |
BEGIN |
|
705 |
-- will then be assignment-cast to return type via INOUT |
|
706 |
RETURN value::cstring; |
|
707 |
END; |
|
708 |
$$; |
|
709 |
|
|
710 |
|
|
711 |
-- |
|
712 |
-- Name: FUNCTION "cast"(value text, ret_type_null anyelement); Type: COMMENT; Schema: util; Owner: - |
|
713 |
-- |
|
714 |
|
|
715 |
COMMENT ON FUNCTION "cast"(value text, ret_type_null anyelement) IS ' |
|
716 |
allows casting to an arbitrary type without eval() |
|
717 |
|
|
718 |
usage: |
|
719 |
SELECT util.cast(''value'', NULL::integer); |
|
720 |
|
|
721 |
note that there does *not* need to be a cast from text to the output type, |
|
722 |
because an INOUT cast is used instead |
|
723 |
(http://www.postgresql.org/docs/9.3/static/sql-createcast.html#AEN69507) |
|
724 |
|
|
725 |
ret_type_null: NULL::ret_type |
|
726 |
'; |
|
727 |
|
|
728 |
|
|
729 |
-- |
|
696 | 730 |
-- Name: cluster_index(regclass); Type: FUNCTION; Schema: util; Owner: - |
697 | 731 |
-- |
698 | 732 |
|
Also available in: Unified diff
schemas/util.sql: added util.cast(), which allows casting to an arbitrary type without eval()