function
function
От:
"Normunds" <normunds@mt.lv>
Дата:
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?
Normunds
Re: [GENERAL] function
От:
Jan Wieck <janwieck@Yahoo.com>
Дата:
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 #
Re: [GENERAL] function
От:
Ian Turner <vectro@pipeline.com>
Дата:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 > 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. Probably best to do this as an embedded perl sql function. Then it is about 3 lines. Ian -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.1 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE5rbnTfn9ub9ZE1xoRAh7uAKCAxqAM9Wo09g6qntF6qJTtp5u+KACgsO9d VvH5BBpn4gIpdrHFAw8x6Jo= =zH55 -----END PGP SIGNATURE-----