Revision 12358
Added by Aaron Marcuse-Kubitza almost 11 years ago
trunk/schemas/util.sql | ||
---|---|---|
2435 | 2435 |
|
2436 | 2436 |
|
2437 | 2437 |
-- |
2438 |
-- Name: replace_suffix(text, text, text); Type: FUNCTION; Schema: util; Owner: - |
|
2438 |
-- Name: replace_suffix(text, text, text, integer); Type: FUNCTION; Schema: util; Owner: -
|
|
2439 | 2439 |
-- |
2440 | 2440 |
|
2441 |
CREATE FUNCTION replace_suffix(str text, old_suffix text, new_suffix text) RETURNS text |
|
2441 |
CREATE FUNCTION replace_suffix(str text, old_suffix text, new_suffix text, max_prefix_len integer DEFAULT 0) RETURNS text
|
|
2442 | 2442 |
LANGUAGE sql IMMUTABLE |
2443 | 2443 |
AS $_$ |
2444 |
SELECT regexp_replace($1, '^(.*)'||util.regexp_quote($2)||'$', '\1'||$3)
|
|
2444 |
SELECT regexp_replace($1, util.truncated_prefixed_name_regexp($2, $4), '\1'||$3)
|
|
2445 | 2445 |
$_$; |
2446 | 2446 |
|
2447 | 2447 |
|
2448 | 2448 |
-- |
2449 |
-- Name: FUNCTION replace_suffix(str text, old_suffix text, new_suffix text, max_prefix_len integer); Type: COMMENT; Schema: util; Owner: - |
|
2450 |
-- |
|
2451 |
|
|
2452 |
COMMENT ON FUNCTION replace_suffix(str text, old_suffix text, new_suffix text, max_prefix_len integer) IS ' |
|
2453 |
max_prefix_len: when str may have been truncated (eg. as a table name) due to the prepending of a prefix, support prefixes up to this length |
|
2454 |
'; |
|
2455 |
|
|
2456 |
|
|
2457 |
-- |
|
2449 | 2458 |
-- Name: reset_col_names(regclass, regclass); Type: FUNCTION; Schema: util; Owner: - |
2450 | 2459 |
-- |
2451 | 2460 |
|
Also available in: Unified diff
schemas/util.sql: replace_suffix(): support strings that have been truncated (eg. as a table name) due to the prepending of a prefix