RE: How to set parameters in 'options'? - Mailing list pgsql-general

From Igor Neyman
Subject RE: How to set parameters in 'options'?
Date
Msg-id DM5PR17MB153249E644BC51B8C6EADE6EDA970@DM5PR17MB1532.namprd17.prod.outlook.com
Whole thread Raw
In response to How to set parameters in 'options'?  (Stefan Keller <sfkeller@gmail.com>)
List pgsql-general
-----Original Message-----
From: Stefan Keller [mailto:sfkeller@gmail.com] 
Sent: Tuesday, January 29, 2019 9:40 AM
To: Postgres General <pgsql-general@postgresql.org>
Subject: How to set parameters in 'options'?

Hi,

I'd like to write a function like this:

create function foo(_host text, _port text, _dbname text) returns void as $$
  create server _server
    foreign data wrapper postgres_fdw
    options (host _host, port _port, dbname _dbname);
    -- ERROR: syntax error at or near "_host"
$$ language sql;

In order to e.g. do:
select foo('111.11.11.11', '5432', 'mydb');

How can I set the parameters in 'options' using those variables?

:Stefan

P.S. Actually I'll put this code in a plggsql function later on.
______________________________________________________________________________________

Use dynamic sql:
https://www.postgresql.org/docs/11/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN

Regards,
Igor Neyman

pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Anonymize Data
Next
From: Adrian Klaver
Date:
Subject: Re: How to set parameters in 'options'?