array_to_column function

Поиск
Список
Период
Сортировка
От David Fetter
Тема array_to_column function
Дата
Msg-id 20041030195439.GA13884@fetter.org
обсуждение исходный текст
Ответы Re: array_to_column function  (Markus Bertheau <twanger@bluetwanger.de>)
Список pgsql-hackers
Kind people,

Here's something I came up with, having accidentally discovered the
ARRAY() constructor (BTW, I think at least some pointer to it should
be in the array section of functions & operators).

CREATE OR REPLACE FUNCTION array_to_column (ANYARRAY)
RETURNS SETOF ANYELEMENT
IMMUTABLE
LANGUAGE plpgsql
AS $$
BEGIN   IF (position('][' IN array_dims($1)) <> 0)   THEN       RAISE EXCEPTION 'Only 1-dimensional arrays are
allowed!';  END IF;   FOR i IN array_lower($1, 1) .. array_upper($1, 1)   LOOP       RETURN NEXT $1[i];   END LOOP;
RETURN;
END;
$$;

Thanks to Markus Bertheau aka ska-fan for help with removing an
unneeded regex compare and with spelling. :)

Cheers,
D
-- 
David Fetter david@fetter.org http://fetter.org/
phone: +1 510 893 6100   mobile: +1 415 235 3778

Remember to vote!


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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Signature change for SPI_cursor_open
Следующее
От: Thomas Hallgren
Дата:
Сообщение: Problems using pgxs on Win32