BUG #17630: pg_dump error

Lists: pgsql-bugs
From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: killerwzb(at)163(dot)com
Subject: BUG #17630: pg_dump error
Date: 2022-10-09 09:22:38
Message-ID: 17630-0947c0a5aa573243@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 17630
Logged by: camel
Email address: killerwzb(at)163(dot)com
PostgreSQL version: 14.5
Operating system: centos7
Description:

Hi guys:
I create table with a upper name ,it is "TABLE2" .I use pg_dump to dump
the table to a custom file,but i get some error.

The first step:
[wangzhibin(at)localhost bin]$ ./psql -U postgres
psql (16devel)
Type "help" for help.

postgres=# create table "TABLE2" (t1 int);
CREATE TABLE

The second step:
[wangzhibin(at)localhost bin]$ ./pg_dump --verbose --host localhost --port 5432
--username postgres --dbname=postgres --format custom --file ~/db.bak
--table TABLE2
pg_dump: last built-in OID is 16383
pg_dump: error: no matching tables were found
[wangzhibin(at)localhost bin]$ ./pg_dump --verbose --host localhost --port 5432
--username postgres --dbname=postgres --format custom --file ~/db.bak
--table "TABLE2"
pg_dump: last built-in OID is 16383
pg_dump: error: no matching tables were found
[wangzhibin(at)localhost bin]$ ./pg_dump --verbose --host localhost --port 5432
--username postgres --dbname=postgres --format custom --file ~/db.bak
--table "table2"
pg_dump: last built-in OID is 16383
pg_dump: error: no matching tables were found


From: Christophe Pettus <xof(at)thebuild(dot)com>
To: killerwzb(at)163(dot)com, PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #17630: pg_dump error
Date: 2022-10-09 22:20:40
Message-ID: 3B75DF91-FB87-4580-88CD-AF6B78ABFA80@thebuild.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

> On Oct 9, 2022, at 02:22, PG Bug reporting form <noreply(at)postgresql(dot)org> wrote:
> I create table with a upper name ,it is "TABLE2" .I use pg_dump to dump
> the table to a custom file,but i get some error.

It's not a bug, but it's kind of an annoying situation. The double quotes on the command line just delimit the name of the table, but the shell strips them off (as you would expect), so pg_dump just gets the bare name. You have to add separate, escaped double-quotes, since the table name requires them:

xof=# create table "TABLE2" (i integer);
CREATE TABLE
xof=#
\q
xof$ pg_dump --dbname=xof --table "TABLE2" > /dev/null
pg_dump: error: no matching tables were found
xof$ pg_dump --dbname=xof --table "\"TABLE2\"" > /dev/null
xof$


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Christophe Pettus <xof(at)thebuild(dot)com>
Cc: killerwzb(at)163(dot)com, PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #17630: pg_dump error
Date: 2022-10-09 22:53:50
Message-ID: 3953507.1665356030@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Christophe Pettus <xof(at)thebuild(dot)com> writes:
>> On Oct 9, 2022, at 02:22, PG Bug reporting form <noreply(at)postgresql(dot)org> wrote:
>> I create table with a upper name ,it is "TABLE2" .I use pg_dump to dump
>> the table to a custom file,but i get some error.

> It's not a bug, but it's kind of an annoying situation. The double quotes on the command line just delimit the name of the table, but the shell strips them off (as you would expect), so pg_dump just gets the bare name. You have to add separate, escaped double-quotes, since the table name requires them:

Another way with slightly fewer keystrokes is

pg_dump ... --table '"TABLE2"'

Of course, if you're also in the habit of putting single-quotes in
your table names, that'll still need some work. The main point is
that there are two layers of quoting that you have to deal with:
the shell's, and then SQL's.

regards, tom lane