1

I want to access different databases from postgresql stored functions.

For example:

CREATE OR REPLACE FUNCTION test ()  RETURNS SETOF volume AS
$BODY$

SELECT * FROM db2.volume
ORDER BY db2.volume.volumeID

$BODY$  
LANGUAGE sql STABLE  
COST 100  
ROWS 1000;

any input will be great help.

Regards, Manasi

1 Answer 1

2

what you need is database link

Sign up to request clarification or add additional context in comments.

3 Comments

Well but in db link is it possible I can change database name at runtime.
why not ? SELECT dblink_connect('conn', 'dbname=yourdb');
CREATE OR REPLACE FUNCTION test (dbname character varying) RETURNS SETOF volume AS $BODY$ SELECT * FROM dblink_connect('dbname=$1') ORDER BY db2.volume.volumeID $BODY$ LANGUAGE sql STABLE COST 100 ROWS 1000;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.