Re: Converting value to array

Поиск
Список
Период
Сортировка
От Michael Fuhr
Тема Re: Converting value to array
Дата
Msg-id 20050205164147.GA23116@winnie.fuhr.org
обсуждение исходный текст
Ответ на Converting value to array  ("Sean Davis" <sdavis2@mail.nih.gov>)
Список pgsql-novice
On Sat, Feb 05, 2005 at 11:12:09AM -0500, Sean Davis wrote:
>
> I have a column in my table block_sizes(varchar) that looks like:
>
> 12,23,
> 234,23,
> 78,64,28,
>
> i.e., comma-separated integer values (and the included trailing comma).
> I would like to convert these each to an array and store in another
> column.

Have you tried string_to_array()?

http://www.postgresql.org/docs/8.0/static/functions-array.html

CREATE TABLE foo (
    strcol    text,
    arraycol  integer[]
);

INSERT INTO foo (strcol) VALUES ('12,23,');
INSERT INTO foo (strcol) VALUES ('234,23,');
INSERT INTO foo (strcol) VALUES ('78,64,28,');

UPDATE foo SET arraycol = string_to_array(rtrim(strcol, ','), ',')::integer[];

SELECT * FROM foo;
  strcol   |  arraycol
-----------+------------
 12,23,    | {12,23}
 234,23,   | {234,23}
 78,64,28, | {78,64,28}
(3 rows)

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

В списке pgsql-novice по дате отправления:

Предыдущее
От: "Sean Davis"
Дата:
Сообщение: Converting value to array
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Converting value to array