From: | Joe Conway <mail(at)joeconway(dot)com> |
---|---|
To: | nolan(at)celery(dot)tssi(dot)com |
Cc: | pgsql general list <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: arrays and insert/select |
Date: | 2003-05-29 05:54:37 |
Message-ID: | 3ED5A09D.30403@joeconway.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
nolan(at)celery(dot)tssi(dot)com wrote:
> I'm loading a table from another (in 7.3.2) and need to build a
> varchar array from a varchar column in the source table.
>
[...snip...]
>
> There doesn't appear to be a to_array function.
>
In 7.4 you'll have other options, but in 7.3.x the only way I can think
of to do this is like this (example is int/int[], but I think you'll get
the picture):
create table a (f int);
insert into a values(1);
create table b (f int[]);
create or replace function singleton_array(int) returns int[] as '
declare
v_arr text;
begin
v_arr := ''{'' || $1 || ''}'';
return v_arr;
end;
' language 'plpgsql';
insert into b (f) select singleton_array(f) from a;
test=# select * from b;
f
-----
{1}
(1 row)
HTH,
Joe
From | Date | Subject | |
---|---|---|---|
Next Message | Saravanan Thulukanam | 2003-05-29 06:49:20 | Advance Function |
Previous Message | Alam Surya | 2003-05-29 04:56:29 | Re: Triggers and Function's |