From: Jan Wieck <janwieck@Yahoo.com>
To: Normunds <normunds@mt.lv>
Cc: pgsql-general@postgresql.org
Cc: pgsql-sql@postgresql.org
Subject: Re: function
Date: Wed, 30 Aug 2000 17:14:10 -0500 (EST)
Message-ID: <200008302214.RAA06005@jupiter.jw.home> (raw)
In-Reply-To: <078001c0129a$a2354ec0$1708050a@mt.lv>
Normunds wrote:
> Hi all,
>
> how can I write function which takes text from one field, replaces
> some characters and puts it in other field? I have array with old and
> new values.
>
> For example:
> old array = {'r', 'Z', 'o'}
> new array = {'s', 'm', 't'}
> old field value = 'Zorro'
> new field value which must calculate this function = 'mtsst'
>
> This function will be used in update trigger.
> Any ideas?
Tcl has a "map" functionality as subcommand of "string". I
think it appeared in version 8.1. To use the example below,
your Tcl installation must be 8.1 or newer when rebuilding
PostgreSQL configured with "--with-tcl" and enable PL/Tcl
with "createlang".
CREATE FUNCTION string_map(text, text) RETURNS text AS '
return [string map $2 $1]
' LANGUAGE 'pltcl';
CREATE
SELECT string_map('Zorro', 'r s Z m o t');
string_map
------------
mtsst
(1 row)
As you see, the old and new arrays are both coded into the
second argument. It is a key, value pair list, with usual Tcl
quoting for lists. Can you convert your arrays to that?
Jan
--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck@Yahoo.com #
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: janwieck@Yahoo.com, normunds@mt.lv, pgsql-general@postgresql.org
Subject: Re: function
In-Reply-To: <200008302214.RAA06005@jupiter.jw.home>
* 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