Can't create a backup of data of a single table
-
05-10-2020 - |
Question
I try to use a command:
pg_dump -U postgres -d "ProjectsManagement" -t public.Statuses -a > path
But it doesn't work and outputs:
pg_dump: соответствующие таблицы не найдены (English: Tables not found)
But this table exists and without a -t
argument it works.
What is happening?
\l
output:
ProjectsManagement | postgres | UTF8 | Russian_Russia.1251 | Russian_Russia.1251 |
Solution
Just taking a look at postgres documentation and samples I've found this specific case:
To specify an upper-case or mixed-case name in -t and related switches, you need to double-quote the name; else it will be folded to lower case (see Patterns). But double quotes are special to the shell, so in turn they must be quoted. Thus, to dump a single table with a mixed-case name, you need something like:
$ pg_dump -t "\"MixedCaseName\"" mydb > mytab.sql
You can read about it here.
OTHER TIPS
if the table's name is not all lower-case, you need to double-quote it, and then single quote the whole schema.table as well, with either '"Statuses"'
or 'public."Statuses"'
:
pg_dump -U postgres -d "ProjectsManagement" -t '"Statuses"' -a > path
pg_dump -U postgres -d "ProjectsManagement" -t 'public."Statuses"' -a > path
The above is for Linux/Unix systems. Windows command line has different behaviour regarding quoting and escaping special characters. So the following (or some of them) work but I'm not sure which is best and safest:
-t "public.""Statuses""" -- works
-t "public.\"Statuses\"" -- works
-t "public.^"Statuses^"" -- NO
-t public."""Statuses""" -- works
-t public."\"Statuses\"" -- works
-t public."^"Statuses^"" -- NO