pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Leif Biberg Kristensen <leif@solumslekt.org>
To: pgsql-sql@postgresql.org
Subject: Re: regexp_replace and search/replace values stored in table
Date: Tue, 27 Apr 2010 16:18:57 +0200
Message-ID: <201004271618.57658.leif@solumslekt.org> (raw)
In-Reply-To: <201004271532.20639.leif@solumslekt.org>
References: <201004271343.48070.leif@solumslekt.org>
	<201004271532.20639.leif@solumslekt.org>

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/



view thread (7+ messages)  latest in thread

Message-ID: <201004271618.57658.leif@solumslekt.org>
Permalink:  ../201004271618.57658.leif@solumslekt.org/
Also on:    postgresql.org/message-id/201004271618.57658.leif@solumslekt.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: leif@solumslekt.org
  Subject: Re: regexp_replace and search/replace values stored in table
  In-Reply-To: <201004271618.57658.leif@solumslekt.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox