Re: Add missing CREATE TABLE IF NOT EXISTS table_name AS EXECUTEquery; - Mailing list pgsql-hackers

From Michael Paquier
Subject Re: Add missing CREATE TABLE IF NOT EXISTS table_name AS EXECUTEquery;
Date
Msg-id 20190215081451.GD2240@paquier.xyz
Whole thread Raw
In response to Re: Add missing CREATE TABLE IF NOT EXISTS table_name AS EXECUTEquery;  (Michael Paquier <michael@paquier.xyz>)
Responses Re: Add missing CREATE TABLE IF NOT EXISTS table_name AS EXECUTEquery;
List pgsql-hackers
On Mon, Feb 11, 2019 at 09:53:59PM +0900, Michael Paquier wrote:
> Let's wait a bit more than the beginning of this week.  I forgot about
> this week's minor release, and it is too late to do something about
> this report now, so we will have to wait until the release had
> happened.

OK, committed down to 9.5.

Another thing I have noticed is the following, which is kind of funky
(just rinse and repeat once):
=# EXPLAIN ANALYZE CREATE TABLE IF NOT EXISTS ac AS SELECT 1;
ERROR:  42P07: relation "ac" already exists
LOCATION:  heap_create_with_catalog, heap.c:1111

The issue here is that we check for IF NOT EXISTS at the high level of
ExecCreateTableAs, however EXPLAIN takes the lower path of
create_ctas_internal() which enforces if_not_exists to false when
building the CreateStmt object to create the relation.  This brings
out a more interesting issue: how should an EXPLAIN behave in this
case?  It has nothing to output as the relation already exists.
--
Michael

Attachment

pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: INSTALL file
Next
From: Michael Paquier
Date:
Subject: Re: 2019-03 CF Summary / Review - Tranche #1