FW: plpgsql function help - Mailing list pgsql-novice

From Tyler Hains
Subject FW: plpgsql function help
Date
Msg-id H000006900b56ba2.1269953212.mailpa.profitpointinc.com@MHS
Whole thread Raw
Responses Re: FW: plpgsql function help
List 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

 

pgsql-novice by date:

Previous
From: dipti shah
Date:
Subject: Get the list of permissions on schema for current user
Next
From: "A. Kretschmer"
Date:
Subject: Re: FW: plpgsql function help