Re: creating array of integer[] out of query - how?

Поиск
Список
Период
Сортировка
От Sam Mason
Тема Re: creating array of integer[] out of query - how?
Дата
Msg-id 20090902141724.GQ5407@samason.me.uk
обсуждение исходный текст
Ответ на Re: creating array of integer[] out of query - how?  ("Massa, Harald Armin" <chef@ghum.de>)
Список pgsql-general
On Wed, Sep 02, 2009 at 03:47:53PM +0200, Massa, Harald Armin wrote:
> ibox=# CREATE TYPE intarr AS (arr int[]);
> CREATE TYPE
> ibox=#  SELECT array(
>       SELECT x::intarr FROM (
>       SELECT array[2,3]
>       UNION ALL
>       SELECT array[3,4]) x(a));
>            ?column?
> -------------------------------
>  {"(\"{2,3}\")","(\"{3,4}\")"}
> (1 Zeile)
>
> .... the result seems to be an array with two strings containing escaped
> string-represenations of arrays :)

I think that's what you want though--PG just formats the literal the
only way it knows how.  You can use the normal array indexing operators
to get the elements out that you want.  For example:

  SELECT x.arr[1].arr[1]
  FROM (SELECT e'{"(\\"{2,3}\\")","(\\"{3,4}\\")"}'::intarr[]) x(arr);

Or from your original query:

  SELECT x.arr[1].arr[1]
  FROM (
    SELECT array(
      SELECT x::intarr FROM (
         SELECT array[2,3]
         UNION ALL
         SELECT array[3,4]) x(a))) x(arr);

If you really do care how the literals are formatted, then you're going
to have to come up with your own data type and associated input and
output functions.

--
  Sam  http://samason.me.uk/

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

Предыдущее
От: Gordon Ross
Дата:
Сообщение: PL/SQL & unset custom variable
Следующее
От: Merlin Moncure
Дата:
Сообщение: Re: creating array of integer[] out of query - how?