How to return an array of values from a function?

From: Siva Palanisamy <siva_p(at)hcl(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: How to return an array of values from a function?
Date: 2011-09-15 06:13:56
Message-ID: 90F0F47595235141A4380FCF01B0185B224141CCB4@CHN-HCLT-EVS07.HCLT.CORP.HCL.IN
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi All,

I wish to return an array of values. Assume, I have a table called contacts. I want to display all the names available from a column in the UI. Hence I need to return that column as an array of values. Please correct me if there is any other solution exist.

Here is the code, I'm trying to execute:

CREATE OR REPLACE FUNCTION get_all_names()
RETURNS TEXT[] AS '
DECLARE
group_data TEXT[];
BEGIN
SELECT display_name INTO group_data FROM contacts;
RETURN group_data;
END;
'LANGUAGE 'plpgsql';

During compilation, I got the below error:

ERROR: array value must start with "{" or dimension information
CONTEXT: PL/pgSQL function "get_all_ names " line 4 at SQL statement

Regards,
Siva.

________________________________
::DISCLAIMER::
-----------------------------------------------------------------------------------------------------------------------

The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only.
It shall not attach any liability on the originator or HCL or its affiliates. Any views or opinions presented in
this email are solely those of the author and may not necessarily reflect the opinions of HCL or its affiliates.
Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of
this message without the prior written consent of the author of this e-mail is strictly prohibited. If you have
received this email in error please delete it and notify the sender immediately. Before opening any mail and
attachments please check them for viruses and defect.

-----------------------------------------------------------------------------------------------------------------------

Responses

Browse pgsql-general by date

  From Date Subject
Next Message AI Rumman 2011-09-15 06:17:03 Re: how to use all the options of EXPLAIN?
Previous Message Toby Corkindale 2011-09-15 05:59:20 Re: how to use all the options of EXPLAIN?