From: | Mikail Majorov <mik(at)nix(dot)org(dot)ru> |
---|---|
To: | "Jerome Chochon" <jerome(dot)chochon(at)ensma(dot)fr> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Add value in an Array |
Date: | 2002-07-25 11:47:45 |
Message-ID: | 20020725154745.6b8f3818.mik@nix.org.ru |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Thu, 25 Jul 2002 13:48:58 +0200
"Jerome Chochon" <jerome(dot)chochon(at)ensma(dot)fr> wrote:
> Hi all.
>
> I am a french student working on a PostgreSQL database.
> So i want to create a view which use a fonction (write in PLPGSQL) .
> This function will take a colum from a table (the column is integer[] based) and add a value in the array.
> So i dont find an operator to make this command.
>
> Someone can help me ?
For example.....
CREATE FUNCTION add_array(text[], text) RETURNS text[] AS '
$_[0] =~ s/[{}"]//g; $_[1] =~ s/[{}"]//g;
my %hs = ();
foreach my $c (split(/,/, $_[0])) { $hs{$c} = 1; }
if ($_[1] ne "") { $hs{$_[1]} = 1; }
return "{" . join(",", (keys %hs)) . "}";
' LANGUAGE 'plperl';
CREATE OPERATOR + (leftarg=text[], rightarg=text, procedure=add_array);
CREATE FUNCTION del_array(text[], text) RETURNS text[] AS '
$_[0] =~ s/[{}"]//g; $_[1] =~ s/[{}"]//g;
my %hs = ();
foreach my $c (split(/,/, $_[0])) { $hs{$c} = 1; }
if ($_[1] ne "") { delete $hs{$_[1]}; }
return "{" . join(",", (keys %hs)) . "}";
' LANGUAGE 'plperl';
CREATE OPERATOR - (leftarg=text[], rightarg=text, procedure=del_array);
--
С уважением,
Михаил Майоров
Таганрогский Узел ЭлектроСвязи
+7 8634 362563
+7 8634 383242 fax only
From | Date | Subject | |
---|---|---|---|
Next Message | Jerome Chochon | 2002-07-25 11:48:58 | Add value in an Array |
Previous Message | Ben-Nes Michael | 2002-07-25 10:55:59 | Is this query possible in PostgreSQL ? |