From: | "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com> |
---|---|
To: | pgsql-novice(at)postgresql(dot)org |
Subject: | Re: FW: plpgsql function help |
Date: | 2010-03-30 13:03:08 |
Message-ID: | 20100330130308.GC18474@a-kretschmer.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
In response to Tyler Hains :
> Hello,
>
>
>
> I am trying to get a function to return an integer field pulled from a
> different database using dblink. I am getting a run-time error. Here is the
> function and the error:
>
>
>
> CREATE OR REPLACE FUNCTION get_db_id()
>
> RETURNS INTEGER AS
>
> $BODY$
>
> DECLARE
>
> client_ids INTEGER[];
>
> db_id INTEGER;
>
> BEGIN
>
> SELECT INTO client_ids DISTINCT client_id FROM clients;
>
>
>
> ERROR: array value must start with "{" or dimension information
>
> SQL state: 22P02
>
> Context: PL/pgSQL function "get_db_id" line 5 at SQL statement
>
>
>
>
>
> Can anyone tell me what I?m doing wrong?
You have defined client_ids as INT[], but your select returns a SET of
integers. You can change it to :
SELECT INTO client_ids array_agg(DISTINCT client_id) FROM clients;
Regards, Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431 2EB0 389D 1DC2 3172 0C99
From | Date | Subject | |
---|---|---|---|
Next Message | Tyler Hains | 2010-03-30 14:00:02 | Re: FW: plpgsql function help |
Previous Message | Tyler Hains | 2010-03-30 12:46:53 | FW: plpgsql function help |