HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMinor

how to dump a case-sensitive table within a specific schema

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
casedumpwithinschemahowsensitivespecifictable

Problem

I'm trying to dump a case-sensitive table named app_auth.User by executing the following command

pg_dump --schema=app_auth -t '"User"' -U em3local -h 127.0.0.1 -Fc -a -f  


but what I'm returned is:

pg_dump: No matching tables were found


If I actually query my DB, the table does exist:

=# SELECT * FROM app_auth."User";
 username | email | password | name | surname | lang | resettoken | userinfo_id | state | tos_accepted | id 
----------+-------+----------+------+---------+------+------------+-------------+-------+--------------+----


any hint?

Solution

When you specifies the schema name to unload it does not mean that it will be default schema to search objects:

nd@postgres=# create schema foobar;
CREATE SCHEMA
nd@postgres=# create table foobar."Foo"();
CREATE TABLE
nd@postgres=# \! pg_dump --schema=foobar -t "Foo"
pg_dump: no matching tables were found


So you should to fully qualify the table name:

nd@postgres=# \! pg_dump --schema=foobar -t 'foobar."Foo"'
--
-- PostgreSQL database dump
--
... etc ...


Excerpt from the documentation (cursive and bold is mine):

The -n and -N (--schema) switches have no effect when -t is used, because tables selected by -t will be dumped regardless of those switches, and non-table objects will not be dumped.

Formerly, writing -t tab would dump all tables named tab, but now it just dumps whichever one is visible in your default search path.

Code Snippets

nd@postgres=# create schema foobar;
CREATE SCHEMA
nd@postgres=# create table foobar."Foo"();
CREATE TABLE
nd@postgres=# \! pg_dump --schema=foobar -t "Foo"
pg_dump: no matching tables were found
nd@postgres=# \! pg_dump --schema=foobar -t 'foobar."Foo"'
--
-- PostgreSQL database dump
--
... etc ...

Context

StackExchange Database Administrators Q#179608, answer score: 9

Revisions (0)

No revisions yet.