Skip site navigation (1) Skip section navigation (2)

Re: function

From: Jan Wieck <janwieck(at)Yahoo(dot)com>
To: Normunds <normunds(at)mt(dot)lv>
Cc: pgsql-general(at)postgresql(dot)org, pgsql-sql(at)postgresql(dot)org
Subject: Re: function
Date: 2000-08-30 22:14:10
Message-ID: 200008302214.RAA06005@jupiter.jw.home (view raw or flat)
Thread:
Lists: pgsql-generalpgsql-sql
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(at)Yahoo(dot)com #



In response to

  • function at 2000-08-30 15:54:51 from Normunds

pgsql-sql by date

Next:From: Ian TurnerDate: 2000-08-31 01:50:09
Subject: Re: function
Previous:From: Zlatko CalusicDate: 2000-08-30 22:13:18
Subject: Re: Optimizing huge inserts/copy's

pgsql-general by date

Next:From: Zlatko CalusicDate: 2000-08-30 22:55:35
Subject: Re: Large selects handled inefficiently?
Previous:From: Tom LaneDate: 2000-08-30 21:41:04
Subject: Re: PG 7.0 vacuum problem

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group