Re: Add value in an Array

From: "Jerome Chochon" <jerome(dot)chochon(at)ensma(dot)fr>
To: "Mikail Majorov" <mik(at)nix(dot)org(dot)ru>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Add value in an Array
Date: 2002-07-25 12:42:20
Message-ID: 026401c233d8$b7aaece0$80a337c1@pclisi17
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thanks but i want to use only PLPGSQL or SQL.
Or perhaps there is a native function in PostgreSQL (like dim_arrays).

Someone have another solution ?

----- Original Message -----
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>
Sent: Thursday, July 25, 2002 1:47 PM
Subject: Re: [GENERAL] Add value in an Array

> 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
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tycho Fruru 2002-07-25 13:10:51 Re: using socket to connect flash to the sql database
Previous Message terry 2002-07-25 12:41:20 FW: pg_clog error