38

When I try to use \i on a file that is not in the psql.exe folder it says C:: permission denied. For example I have a file with SQL command at C:\Users\Work\Desktop\School Work\load_database.sql and when I type \i "C:\Users\Work\Desktop\School Work\load_database.sql" it says C:: permission denied. How can I fix this?

I found a work around here where you copy the .sql file to the same folder as psql.exe is in.

By the way, does \i stand for import?

0

2 Answers 2

70

You've just run into a peculiarity of psql on Windows.

In my comment I just wanted to exclude the possibility that you really didn't have the necessary permission. Then it turned out that even on Windows, you have to use 'normal' slashes instead of backslashes, that is:

\i 'C:/Users/Work/Desktop/School Work/load_database.sql'

should work fine regardless which folder you start psql from. Notice that I used single quotes - with double quotes you'd got

"C:/Users/Work/Desktop/School Work/load_database.sql": Invalid argument
5
  • 1
    Got it thanks. How did you know to use single and not double quotes? Is that a general rule for postgres or what's the difference?
    – Celeritas
    Commented Dec 5, 2012 at 0:37
  • 1
    @Celeritas I think it is the result of a conflict of how Windows uses double quotes in paths and how psql (and PostgreSQL) use it in identifiers. Commented Dec 5, 2012 at 5:59
  • this didn´t work for me in windows10, forward slashes and all, user68006's answer did, though Commented Dec 3, 2018 at 3:09
  • 1
    @Scaramouche thanks for the feedback! Apparently, not all permissions denied are created equal. Commented Dec 4, 2018 at 13:40
  • 2
    Backslashes can be used if they're escaped (by being doubled) and inside a string delimited by single quotes: \i 'c:\\some\\path\\myscript.sql' does work as well as \i 'c:/some/path/myscript.sql' Commented Aug 3, 2020 at 13:53
9

Put the file in some directory with full permission to everyone, like 'c:\tmp'

OR

Set read privileges to the file you want to import.

I put 'Everyone' reading permission.

After importing the file, you could revoke that permission.

windows file properties

1
  • There's no permissions issue here -- it's that the string has to be written in a way that pqsl likes. We know the permissions aren't a problem because the error says "C:" is the problem, not the whole file name.
    – MikeB
    Commented May 30, 2021 at 22:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.