Revision 14145
Added by Aaron Marcuse-Kubitza over 10 years ago
trunk/schemas/util.sql | ||
---|---|---|
3875 | 3875 |
|
3876 | 3876 |
|
3877 | 3877 |
-- |
3878 |
-- Name: remove_suffix(text, text, boolean); Type: FUNCTION; Schema: util; Owner: - |
|
3879 |
-- |
|
3880 |
|
|
3881 |
CREATE FUNCTION remove_suffix(suffix text, str text, require boolean DEFAULT true) RETURNS text |
|
3882 |
LANGUAGE sql IMMUTABLE |
|
3883 |
AS $$ |
|
3884 |
SELECT CASE |
|
3885 |
WHEN substring(str from 1+(length(str)-length(suffix))) = suffix THEN |
|
3886 |
substring(str from 1 for length(str)-length(suffix)) |
|
3887 |
WHEN NOT require THEN str |
|
3888 |
ELSE |
|
3889 |
util.raise('data_exception', 'str does not end with suffix ' |
|
3890 |
||quote_nullable(suffix)||': '||str)::text |
|
3891 |
END |
|
3892 |
$$; |
|
3893 |
|
|
3894 |
|
|
3895 |
-- |
|
3878 | 3896 |
-- Name: rename_cols(regclass, anyelement); Type: FUNCTION; Schema: util; Owner: - |
3879 | 3897 |
-- |
3880 | 3898 |
|
Also available in: Unified diff
schemas/util.sql: added remove_suffix()