array_to_column function - Mailing list pgsql-hackers

From David Fetter
Subject array_to_column function
Date
Msg-id 20041030195439.GA13884@fetter.org
Whole thread Raw
Responses Re: array_to_column function
List 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 by date:

Previous
From: Tom Lane
Date:
Subject: Re: Signature change for SPI_cursor_open
Next
From: Thomas Hallgren
Date:
Subject: Problems using pgxs on Win32