postgresqlpsql

How to use the \i command in SQL-Shell?


I'm new to PostgreSQL and I wanted to use or run a specific file on the SQL-Shell on windows but I`m getting some errors of what I think is not making sense from my knowledge.

I ran the following...

\i 'C: \Users\Username\Documents\person.sql' : No such file or directory

I don`t know why this is not functioning with the quotes and by default this file exists, which I downloaded from a website!

Through my experimentation, I ran the following again without quotes with a different error

\i C: \Users\Username\Documents\person.sql : Permission denied

I don't know why it says at first it doesn't exist but later getting no permission over the file. My question is what is the problem with the following executions and is something wrong with my running?

I looked at this site and saw common problems but it couldn't help me further!

Thanks!


Solution

  • Although not very traditionally Windows-y, using forward slashes should fix you right up. Try this:

    \i C:/Users/Username/Documents/person.sql
    

    You can also go the route of escaping backslashes like \\, but it's probably not worth the trouble.