Revision 14144
Added by Aaron Marcuse-Kubitza over 10 years ago
util.sql | ||
---|---|---|
3857 | 3857 |
|
3858 | 3858 |
|
3859 | 3859 |
-- |
3860 |
-- Name: remove_prefix(text, text, boolean); Type: FUNCTION; Schema: util; Owner: - |
|
3861 |
-- |
|
3862 |
|
|
3863 |
CREATE FUNCTION remove_prefix(prefix text, str text, require boolean DEFAULT true) RETURNS text |
|
3864 |
LANGUAGE sql IMMUTABLE |
|
3865 |
AS $$ |
|
3866 |
SELECT CASE |
|
3867 |
WHEN substring(str from 1 for length(prefix)) = prefix THEN |
|
3868 |
substring(str from 1+length(prefix)) |
|
3869 |
WHEN NOT require THEN str |
|
3870 |
ELSE |
|
3871 |
util.raise('data_exception', 'str does not start with prefix ' |
|
3872 |
||quote_nullable(prefix)||': '||str)::text |
|
3873 |
END |
|
3874 |
$$; |
|
3875 |
|
|
3876 |
|
|
3877 |
-- |
|
3860 | 3878 |
-- Name: rename_cols(regclass, anyelement); Type: FUNCTION; Schema: util; Owner: - |
3861 | 3879 |
-- |
3862 | 3880 |
|
Also available in: Unified diff
schemas/util.sql: added remove_prefix()