Обсуждение: pg_restore -t table : can silently omit constraints

Поиск
Список
Период
Сортировка

pg_restore -t table : can silently omit constraints

От
"Erik Rijkers"
Дата:
(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

Re: pg_restore -t table : can silently omit constraints

От
Tom Lane
Дата:
"Erik Rijkers" <er@xs4all.nl> writes:
> I ran into a bug in pg_restore, where it silently omits
> to restore a constraint (here a primary key):

pg_restore's notion of what -t means is very much more restricted than
pg_dump's is.  We might change this someday, but don't hold your breath
(ie, it's a missing feature not a bug).

In the example at hand I'd suggest just using the -t switch on the dump
side and not passing anything to pg_restore.

            regards, tom lane