pg_restore -t table : can silently omit constraints

From: "Erik Rijkers" <er(at)xs4all(dot)nl>
To: pgsql-bugs(at)postgresql(dot)org
Subject: pg_restore -t table : can silently omit constraints
Date: 2009-04-28 21:54:02
Message-ID: 4833.156.83.1.81.1240955642.squirrel@webmail.xs4all.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

(linux/Centos 5.2, postgres 84beta1, but also 8.3)

Hello,

I ran into a bug in pg_restore, where it silently omits
to restore a constraint (here a primary key):

(this is 8.4 beta 1, but the same occurs in 8.3)

echo "
drop table if exists public.j;
create table public.j (jnr integer NOT NULL primary key);
" | psql -d test ;

psql -d test -c "\d+ public.j"

pg_dump -F c -f ./public_j.dump -t j test

psql -d test -c "drop table if exists public.j; "

pg_restore -v -c -d test -t j ./public_j.dump

The above will give the following output:

DROP TABLE
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "j_pkey" for table "j"
CREATE TABLE
Table "public.j"
Column | Type | Modifiers | Storage | Description
--------+---------+-----------+---------+-------------
jnr | integer | not null | plain |
Indexes:
"j_pkey" PRIMARY KEY, btree (jnr)
Has OIDs: no

DROP TABLE
pg_restore: connecting to database for restore
pg_restore: dropping TABLE j
pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 1490; 1259 17135 TABLE j rijkers
pg_restore: [archiver (db)] could not execute query: ERROR: table "j" does not exist
Command was:
DROP TABLE public.j;
pg_restore: creating TABLE j
pg_restore: restoring data for table "j"
pg_restore: setting owner and privileges for TABLE j
WARNING: errors ignored on restore: 1
Table "public.j"
Column | Type | Modifiers | Storage | Description
--------+---------+-----------+---------+-------------
jnr | integer | not null | plain |
Has OIDs: no

Result: table j gets restored, but without pk.

Although it can be easily worked around, I think this should have behaved differently. It should
have given an error about not restoring the primary key. ( Maybe it would even be preferrable if
it refused to do this incomplete restore).

thanks,

Erik Rijkers

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2009-04-28 22:37:09 Re: pg_restore -t table : can silently omit constraints
Previous Message Bertrand Yohan Breyton Sanial 2009-04-28 19:26:08 Problème password