Using the same script for Postgres COPY in Windows and Ubuntu
Published on 7/23/2014
As per my previous blog post, you should store shared application data in %ProgramData% (Windows) or /srv (Ubuntu).
Let’s say you download Geonames’ allCountries.zip file and unzipped it and put it into your shared application data folder. How can we access these different O/S paths using the same SQL script with Postgres?
One way would be to create a symlink on Windows from /srv to %ProgramData%, then you can use the following script on either Windows or Ubuntu:
copy geonames
from '/srv/geonames/allCountries.txt'
with (
format text,
null ''
)
To create a symlink in Windows, run Command Prompt as an admin:
mklink /d c:\srv %ProgramData%
It would be great if the Postgres guys would let us use O/S environment variables (envvars) in file path, like '$SharedAppData/geonames/allCountries.txt' , then you’d only have to define a common envvar in Linux and Windows.