title: Postgresql - pass parameters to COPY in an sql script
body: <p>I can use the <code>-v v1=foo</code> syntax just fine for queries in my sql script, but I can't figure out how to use that parameter in a copy statement. I'd like to execute the script like:</p>
  <pre><code>psql -d my_db -f ./exports.sql -v v1=&quot;'/Users/username/test.json'&quot;
  </code></pre>
  <p>And in the script do some version of:</p>
  <pre><code>copy (
   select * from bar     
  ) to :v1;
  </code></pre>
  <p>or</p>
  <pre><code>DO $$ 
  BEGIN
    EXECUTE
     'copy (select * from bar) to ' || :v1;
  END $$
  </code></pre>
  <p>or</p>
  <pre><code>DO $$ 
  BEGIN
    EXECUTE
     format('copy (select * from bar) to %L',:v1);
  END $$
  </code></pre>
  <p>But none of the above work :(</p>