Re: regexp_replace and search/replace values stored in table

From: Leif Biberg Kristensen <leif(at)solumslekt(dot)org>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: regexp_replace and search/replace values stored in table
Date: 2010-04-27 14:18:57
Message-ID: 201004271618.57658.leif@solumslekt.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Followup. Replaced Big Ugly Function with:

CREATE OR REPLACE FUNCTION _my_expand(TEXT) RETURNS TEXT AS $$
-- private func, expand various compact links
DECLARE
str TEXT = $1;
links RECORD;

BEGIN
FOR links IN SELECT short_link, long_link FROM short_links LOOP
str := REGEXP_REPLACE(str, links.short_link, links.long_link, 'g');
END LOOP;
RETURN str;
END
$$ LANGUAGE plpgsql IMMUTABLE;

By the way, those who haven't read this gem should probably do so:
<http://database-programmer.blogspot.com/2008/05/minimize-code-maximize-
data.html>

regards,
--
Leif Biberg Kristensen
http://solumslekt.org/

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Gary Chambers 2010-04-28 16:22:23 Inserting Multiple Random Rows
Previous Message Leif Biberg Kristensen 2010-04-27 13:32:20 Re: regexp_replace and search/replace values stored in table