2

I am searching if there is a wildcard assigned to the \ meta-commandsSee description - meta-commands in Postgresql.

for example..

postgresql=> \copy scheme.table FROM 'D:\path\to\%.csv' DELIMITER ';' CSV ENCODING 'LATIN1';

Make notice of the % in the example provided - A known declaration of wildcards could be _, %, . or *. But I do not seem to find documentation of wildcards in /meta-commands for Postresql.

Evan Carroll
65.7k50 gold badges259 silver badges511 bronze badges
asked Dec 4, 2016 at 22:17

1 Answer 1

2

First \COPY isn't postgresql. That's the client psql. From the docs,

Do not confuse COPY with the psql instruction \copy. \copy invokes COPY FROM STDIN or COPY TO STDOUT, and then fetches/stores the data in a file accessible to the psql client. Thus, file accessibility and access rights depend on the client rather than the server when \copy is used.

No, psql does not provide filename completion. However there are other wrapper around COPY FROM STDIN that are not psql and they do. For instance pgloader provides FROM [ ALL FILENAMES | [ FIRST ] FILENAME ] MATCHING

The same clause can also be applied to several files with using the spelling FROM ALL FILENAMES MATCHING and a regular expression. The whole matching clause must follow the following rule:

And on top of that you can always use bash or whatever shell you're using to launch psql. Example with bash filename expansion.

for i in *.csv;
 do psql -c "\copy scheme.table FROM $$D:\path\to\$i.csv$$ DELIMITER ';' CSV ENCODING 'LATIN1';"
done;

Power-shell certainly also provides filename expansion. Google for it if you're on Windows 8+.

answered Dec 5, 2016 at 0:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.