lease=# COPY dhcpd_data (ip_address, start_time, end_time, mac_address, machine_name) FROM '~/outputcsvre.csv' DELIMITER ',' CSV HEADER;
ERROR: could not open file "~/outputcsvre.csv" for reading: No such file or directory
if i define the path as '/home/rihiraj12/outputcsvre.csv', it works fine.
Yes, that's normal.
You don't really have a directory called
~. When you execute a command on the command line, the shell will expand~to/home/rihiraj12before running the program. But here you're not using the shell, so~is interpreted literally.As a workaround you could say
But note that the
COPYcommand is executed by the server, so this will make the server spawn acatcommand and use the home directory of the PostgreSQL server.To specify the file from your own point of view, you can (in psql) use the
\copymeta-command (which has the same syntax asCOPY):This will use your own home directory as
~.