public inbox for [email protected]  
help / color / mirror / Atom feed
CREATE TABLE AS, section  IF NOT EXISTS should clarify what happens to the data
5+ messages / 3 participants
[nested] [flat]

* CREATE TABLE AS, section  IF NOT EXISTS should clarify what happens to the data
@ 2022-02-09 13:02  PG Doc comments form <[email protected]>
  0 siblings, 1 reply; 5+ messages in thread

From: PG Doc comments form @ 2022-02-09 13:02 UTC (permalink / raw)
  To: [email protected]; +Cc: [email protected]

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.


^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: CREATE TABLE AS, section  IF NOT EXISTS should clarify what happens to the data
@ 2022-07-15 01:08  Bruce Momjian <[email protected]>
  parent: PG Doc comments form <[email protected]>
  0 siblings, 1 reply; 5+ messages in thread

From: Bruce Momjian @ 2022-07-15 01:08 UTC (permalink / raw)
  To: [email protected]; [email protected]

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.

-- 
  Bruce Momjian  <[email protected]>        https://momjian.us
  EDB                                      https://enterprisedb.com

  Indecision is a decision.  Inaction is an action.  Mark Batterson



Attachments:

  [text/x-diff] exists.diff (830B, 2-exists.diff)
  download | inline diff:
diff --git a/doc/src/sgml/ref/create_table_as.sgml b/doc/src/sgml/ref/create_table_as.sgml
index 07558ab56c..4d6a1e72d5 100644
--- a/doc/src/sgml/ref/create_table_as.sgml
+++ b/doc/src/sgml/ref/create_table_as.sgml
@@ -100,9 +100,9 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI
     <term><literal>IF NOT EXISTS</literal></term>
     <listitem>
      <para>
-      Do not throw an error if a relation with the same name already exists.
-      A notice is issued in this case. Refer to <xref linkend="sql-createtable"/>
-      for details.
+      Do not throw an error if a relation with the same name already
+      exists; simply issue a notice and leave the table unmodified. Refer
+      to <xref linkend="sql-createtable"/> for details.
      </para>
     </listitem>
    </varlistentry>


^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: CREATE TABLE AS, section IF NOT EXISTS should clarify what happens to the data
@ 2022-07-15 01:47  David G. Johnston <[email protected]>
  parent: Bruce Momjian <[email protected]>
  0 siblings, 1 reply; 5+ messages in thread

From: David G. Johnston @ 2022-07-15 01:47 UTC (permalink / raw)
  To: Bruce Momjian <[email protected]>; +Cc: [email protected]; Pg Docs <[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.


^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: CREATE TABLE AS, section IF NOT EXISTS should clarify what happens to the data
@ 2022-07-18 19:43  Bruce Momjian <[email protected]>
  parent: David G. Johnston <[email protected]>
  0 siblings, 1 reply; 5+ messages in thread

From: Bruce Momjian @ 2022-07-18 19:43 UTC (permalink / raw)
  To: David G. Johnston <[email protected]>; +Cc: [email protected]; Pg Docs <[email protected]>

fOn Thu, Jul 14, 2022 at 06:47:19PM -0700, David G. Johnston wrote:
> 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 tried to go in that direction, but couldn't clearly name the
SELECT/VALUES part of the CREATE TABLE AS query because CREATE TABLE
AS is also a query.  I felt trying to say we ran the CREATE TABLE AS
query but not the SELECT/VALUES of the query was just too confusing.  I
used "simply issue a notice" as implying that nothing else happens,
which I considered sufficient.
> 
> I've removed the xref to create table as there is nothing additional there of
> material benefit - the sentence:

Okay, removed.  Updated patch attached.

-- 
  Bruce Momjian  <[email protected]>        https://momjian.us
  EDB                                      https://enterprisedb.com

  Indecision is a decision.  Inaction is an action.  Mark Batterson



Attachments:

  [text/x-diff] exists.diff (767B, 2-exists.diff)
  download | inline diff:
diff --git a/doc/src/sgml/ref/create_table_as.sgml b/doc/src/sgml/ref/create_table_as.sgml
index 07558ab56c..8429333e3a 100644
--- a/doc/src/sgml/ref/create_table_as.sgml
+++ b/doc/src/sgml/ref/create_table_as.sgml
@@ -100,9 +100,8 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI
     <term><literal>IF NOT EXISTS</literal></term>
     <listitem>
      <para>
-      Do not throw an error if a relation with the same name already exists.
-      A notice is issued in this case. Refer to <xref linkend="sql-createtable"/>
-      for details.
+      Do not throw an error if a relation with the same name already
+      exists; simply issue a notice and leave the table unmodified.
      </para>
     </listitem>
    </varlistentry>


^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: CREATE TABLE AS, section IF NOT EXISTS should clarify what happens to the data
@ 2022-08-12 14:58  Bruce Momjian <[email protected]>
  parent: Bruce Momjian <[email protected]>
  0 siblings, 0 replies; 5+ messages in thread

From: Bruce Momjian @ 2022-08-12 14:58 UTC (permalink / raw)
  To: David G. Johnston <[email protected]>; +Cc: [email protected]; Pg Docs <[email protected]>

On Mon, Jul 18, 2022 at 03:43:03PM -0400, Bruce Momjian wrote:
> fOn Thu, Jul 14, 2022 at 06:47:19PM -0700, David G. Johnston wrote:
> > 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 tried to go in that direction, but couldn't clearly name the
> SELECT/VALUES part of the CREATE TABLE AS query because CREATE TABLE
> AS is also a query.  I felt trying to say we ran the CREATE TABLE AS
> query but not the SELECT/VALUES of the query was just too confusing.  I
> used "simply issue a notice" as implying that nothing else happens,
> which I considered sufficient.
> > 
> > I've removed the xref to create table as there is nothing additional there of
> > material benefit - the sentence:
> 
> Okay, removed.  Updated patch attached.

Patch applied back to PG 10.

-- 
  Bruce Momjian  <[email protected]>        https://momjian.us
  EDB                                      https://enterprisedb.com

  Indecision is a decision.  Inaction is an action.  Mark Batterson







^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2022-08-12 14:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-02-09 13:02 CREATE TABLE AS, section  IF NOT EXISTS should clarify what happens to the data PG Doc comments form <[email protected]>
2022-07-15 01:08 ` Bruce Momjian <[email protected]>
2022-07-15 01:47   ` Re: CREATE TABLE AS, section IF NOT EXISTS should clarify what happens to the data David G. Johnston <[email protected]>
2022-07-18 19:43     ` Re: CREATE TABLE AS, section IF NOT EXISTS should clarify what happens to the data Bruce Momjian <[email protected]>
2022-08-12 14:58       ` Re: CREATE TABLE AS, section IF NOT EXISTS should clarify what happens to the data Bruce Momjian <[email protected]>

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