Can ARRAY( ... ) generate text[][]?

Поиск
Список
Период
Сортировка
От J. Greg Davidson
Тема Can ARRAY( ... ) generate text[][]?
Дата
Msg-id 1276210788.8479.16.camel@shevek.puuhonua.org
обсуждение исходный текст
Ответы Re: Can ARRAY( ... ) generate text[][]?  (Merlin Moncure <mmoncure@gmail.com>)
Список pgsql-general
Hi fellow PostgreSQL hackers!

I tried to write an SQL glue function to turn an array
of alternating key/value pairs into an array of arrays
and got the message

ERROR:  42704: could not find array type for data type text[]

-- BEGIN CODE

-- Here's a simplified example:

CREATE OR REPLACE
FUNCTION text__(variadic text[]) RETURNS text[][] AS $$
SELECT ARRAY(
      SELECT ARRAY[ $1[i], $1[i+1] ]
      FROM generate_series(1, array_upper($1,1), 2) i
)
$$ LANGUAGE sql;

-- Here's what I really wanted:

CREATE OR REPLACE
FUNCTION xpath_(text, xml, variadic text[]) RETURNS xml AS $$
    SELECT ( xpath($1,$2,ARRAY(
      SELECT ARRAY[ $3[i], $3[i+1] ]
      FROM generate_series(1, array_upper($3,1), 2) i
    )    )    )[1]::xml
$$ LANGUAGE sql;

-- END CODE

Is there any decent way to do this in SQL, or do I need
to write it in a procedural language?

Thanks,

_Greg

J. Greg Davidson


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

Предыдущее
От: Alan Hodgson
Дата:
Сообщение: Re: database response slows while pg_dump is running (8.4.2)
Следующее
От: "John T. Dow"
Дата:
Сообщение: Re: Re: Error on Windows server could not open relation base/xxx/xxx Permission denied