On 2/1/22 05:42, aditya desai wrote:
> Hi All,
> how can I pass variables in dblink_connect_u ?
>
> Current code hardcoded DB name:
> perform * from dblink_connect_u('myconn','dbname=mydb');
>
> Expected:
> databasename=current_database();
> perform * from dblink_connect_u('myconn','dbname=databasename');
>
> databasename is getting considered as text.
Correct, it is a string literal. So just create the string literal using
string manipulation functionality -- e.g.:
SELECT
dblink_connect_u('myconn','dbname=' ||
current_database());
dblink_connect_u
------------------
OK
(1 row)
HTH,
Joe
--
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development