FAQ
I have following function expectation is I want to return the items in array
so....I could call this from another function where I could traverse through
the each array element....


CREATE OR REPLACE FUNCTION get_role_id_list_for_type(INTEGER)
RETURNS INTEGER[] AS $$
DECLARE
rolelist INTEGER [];
BEGIN
SELECT INTO rolelist role_id FROM roles WHERE role_type = $1;
RETURN rolelist;
END;
$$ LANGUAGE 'plpgsql';


But when I call the function it gives following error......

ERROR: array value must start with "{" or dimension information
CONTEXT: PL/pgSQL function "get_role_id_list_for_type" line 4 at select
into variables

Could someone please help.....thanks so much in advance



--
View this message in context: http://postgresql.1045698.n5.nabble.com/Newbiee-Pls-help-tp4647358p4647358.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

Search Discussions

  • Jens Wilke at Jul 29, 2011 at 7:27 pm

    On Freitag, 29. Juli 2011, woow wrote:

    I have following function expectation is I want to return the
    items in array
    SELECT INTO rolelist role_id FROM roles WHERE role_type =
    $1; RETURN rolelist;
    Hi,

    you've to use array_agg:
    SELECT INTO rolelist array_agg(role_id) FROM roles WHERE
    role_type = $1;

    Regards, Jens

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppgsql-general @
categoriespostgresql
postedJul 29, '11 at 3:16p
activeJul 29, '11 at 7:27p
posts2
users2
websitepostgresql.org
irc#postgresql

2 users in discussion

Woow: 1 post Jens Wilke: 1 post

People

Translate

site design / logo © 2022 Grokbase