Re: `pg_restore --if-exists` clarification - Mailing list pgsql-docs

From David G. Johnston
Subject Re: `pg_restore --if-exists` clarification
Date
Msg-id CAKFQuwbM2s5Naeb4SZted17zM=r_-C8w07-Bw-SyYd1b8a4LRA@mail.gmail.com
Whole thread Raw
In response to Re: `pg_restore --if-exists` clarification  (Gulyás Attila <toraritte@gmail.com>)
Responses Re: `pg_restore --if-exists` clarification
List pgsql-docs
On Thursday, September 28, 2023, Gulyás Attila <toraritte@gmail.com> wrote:
So `--if-exists` simply suppresses any notice / warning that would occur?

That switch causes the drop DDL produced by pg_restore to include if exists clauses.  The server then simply treats the DDL as a no-op if said object being dropped cannot be found.



But "failure" is not what happens.  If you read the part regarding --clean, you will see that it says:

(Unless --if-exists is used, this might generate some harmless error messages, if any objects were not present in the destination database.) [emphasis added]

with extra emphasis on the word "harmless" --  no failure is caused; the restore proceeds just fine.  

If anything were to change in this regard, it might be better to reconsider what we call the message (i.e.what language pg_restore emits in this scenario.)  It's true, I suppose, in a literal sense that it's an error in that pg_restore couldn't drop a table when instructed to, where no such table exists.  But pragmatically it doesn't matter, so why not reclassify this as a "warning" or a "notice"?

Because pg_restore is just a client and it is repeating back what the server tells it.  And for the server it is an error to drop an object that doesn’t exist.

psql and pg_restore, as clients, can choose to ignore the errors they see, regardless of what kind of error it is, but they don’t take on the added burden of trying to reclassify errors into something else.

David J.

pgsql-docs by date:

Previous
From: Gulyás Attila
Date:
Subject: Re: `pg_restore --if-exists` clarification
Next
From: Tom Lane
Date:
Subject: Re: `pg_restore --if-exists` clarification