public inbox for [email protected]  
help / color / mirror / Atom feed
From: David G. Johnston <[email protected]>
To: Bruce Momjian <[email protected]>
Cc: [email protected]
Cc: Pg Docs <[email protected]>
Subject: Re: CREATE TABLE AS, section IF NOT EXISTS should clarify what happens to the data
Date: Thu, 14 Jul 2022 18:47:19 -0700
Message-ID: <CAKFQuwY30ro-xosyLZc=qFO3UhnudwvHO4oOJDqGawdQrtUWSA@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
	<[email protected]>

On Thu, Jul 14, 2022 at 6:08 PM Bruce Momjian <[email protected]> wrote:

> On Wed, Feb  9, 2022 at 01:02:51PM +0000, PG Doc comments form wrote:
> > The following documentation comment has been logged on the website:
> >
> > Page: https://www.postgresql.org/docs/14/sql-createtableas.html
> > Description:
> >
> > If I create a table with CREATE TABLE IF NOT EXISTS table_name AS, and
> the
> > table exists already, I get a NOTICE instead of an ERROR.
> >
> > I wanted to have it clarified explicitly that the data from the SELECT
> > statement is ignored in this case.
>
> Good point.  Attached is a documentation patch to clarify this.
>
>
Not only is the existing table not modified, I think that the select query
portion of the command is never even executed.  That would seem to be
useful knowledge to have.

Maybe something like:

<para>
 Do not throw an error if a relation with the same name already exists.
 A notice is issued in this case.
 If <literal>WITH DATA</literal> is specified (the default) the execution
of the parsed query does not happen, leaving the existing table with its
existing contents.
</para>

I mention parsing since the command itself will fail if the query is
invalid even if a table already exists.  But any potential runtime errors
(or even side-effects) will not happen.

I've removed the xref to create table as there is nothing additional there
of material benefit - the sentence:

"Note that there is no guarantee that the existing relation is anything
like the one that would have been created."

is basically what we are adding here but this has more detail.

David J.


reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected]
  Subject: Re: CREATE TABLE AS, section IF NOT EXISTS should clarify what happens to the data
  In-Reply-To: <CAKFQuwY30ro-xosyLZc=qFO3UhnudwvHO4oOJDqGawdQrtUWSA@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox