On Thu, 25 Jul 2002 13:48:58 +0200
"Jerome Chochon" <jerome.chochon@ensma.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