FW: plpgsql function help

From: "Tyler Hains" <thains(at)profitpointinc(dot)com>
To: pgsql-novice <pgsql-novice(at)postgresql(dot)org>
Subject: FW: plpgsql function help
Date: 2010-03-30 12:46:53
Message-ID: H000006900b56ba2.1269953212.mailpa.profitpointinc.com@MHS
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

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;

SELECT INTO db_id dblink('dbname=system',

'SELECT database_id FROM clients WHERE client_id =
'||client_ids[0]);

RETURN db_id;

END;

$BODY$

LANGUAGE 'plpgsql' IMMUTABLE

COST 100;

********** Error **********

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?

Thanks,

Tyler Hains

ProfitPoint, Inc.

www.profitpointinc.com

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message A. Kretschmer 2010-03-30 13:03:08 Re: FW: plpgsql function help
Previous Message dipti shah 2010-03-30 11:05:27 Get the list of permissions on schema for current user