chrismarx
chrismarx

Reputation: 12555

Postgresql - pass dynamic file path to COPY in an sql script called from psql

This is very similar to the question here:

Postgresql - pass parameters to COPY in an sql script

But I'm stuck on how to use the format strategy that totally works when copying to a file, but I need to copy from a file, and pass in part of the file path:

--this doesnt work
SELECT format(
      $$copy mytable(mycolums) from %L || 'my/file/path.csv'$$,
      :v1
   ) \gexec

Upvotes: 0

Views: 513

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 247455

Put the concatenation into the argument to format:

SELECT format(
      $$copy mytable(mycolums) from %L$$,
      :v1 || 'my/file/path.csv'
   ) \gexec

Upvotes: 1

Related Questions