Re: How to return an array of values from a function?

Поиск
Список
Период
Сортировка
От Sim Zacks
Тема Re: How to return an array of values from a function?
Дата
Msg-id 4E71AA98.1060206@compulab.co.il
обсуждение исходный текст
Ответ на How to return an array of values from a function?  (Siva Palanisamy <siva_p@hcl.com>)
Список pgsql-general
<meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
    body p { margin-bottom: 0cm; margin-top: 0pt; }

  <body style="direction: ltr;"
    bidimailui-detected-decoding-type="latin-charset" bgcolor="#ffffff"
    text="#000000">
    On 09/15/2011 09:13 AM, Siva Palanisamy wrote:
    <blockquote
cite="mid:90F0F47595235141A4380FCF01B0185B224141CCB4@CHN-HCLT-EVS07.HCLT.CORP.HCL.IN"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html;
        charset=ISO-8859-1">
      <meta name="Generator" content="Microsoft Word 12 (filtered
        medium)">

<!--
 /* Font Definitions */
 @font-face
    {font-family:"Cambria Math";
    panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
    {font-family:Calibri;
    panose-1:2 15 5 2 2 2 4 3 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
    {margin:0in;
    margin-bottom:.0001pt;
    font-size:11.0pt;
    font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
    {mso-style-priority:99;
    color:blue;
    text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
    {mso-style-priority:99;
    color:purple;
    text-decoration:underline;}
span.EmailStyle17
    {mso-style-type:personal-compose;
    font-family:"Calibri","sans-serif";
    color:windowtext;}
.MsoChpDefault
    {mso-style-type:export-only;}
@page Section1
    {size:8.5in 11.0in;
    margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
    {page:Section1;}
-->







        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


    Try
    <blockquote
cite="mid:90F0F47595235141A4380FCF01B0185B224141CCB4@CHN-HCLT-EVS07.HCLT.CORP.HCL.IN"
      type="cite">

        --SELECT display_name INTO group_data FROM
          contacts;


    select array(select display_name from contacts) into group_data;
    <blockquote
cite="mid:90F0F47595235141A4380FCF01B0185B224141CCB4@CHN-HCLT-EVS07.HCLT.CORP.HCL.IN"
      type="cite">

        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.

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

Предыдущее
От: Thomas Kellerer
Дата:
Сообщение: Re: Problem with the 9.1 one-click installer Windows7 64bit
Следующее
От: Yang Zhang
Дата:
Сообщение: Why is this query running slowly?