Is there a way in SQL to import ALL csv contained in a directory to my postgres table ?
Thank you for your help.
Is there a way in SQL to import ALL csv contained in a directory to my postgres table ? Thank you for your help. |
||||
add comment |
This isn't PostgreSQL specific at all. You need to use a loop to invoke All of these tasks are done with the operating system command prompt tools, they're not to do with PostgreSQL. To concatenate the files and run the result:
To loop over them using
I'm sure the 3rd way is possible too. This might work (the equivalent works in a real shell on a unix box) but is untested as I don't have Windows conveniently to hand:
As far as I know none of these guarantee that the files are run in any particular order. You'd need to look up the documentation on the Windows shell. Personally - I recommend doing this sort of thing in Powershell, or in Perl or some other less awful scripting language than the cmd.exe batch language. Either way, all the files must have the system default 1-byte text encoding or must contain an explicit |
|||||
|
copy *.csv all.txt
– Tomas Greif Feb 8 at 19:49