Re: Add missing CREATE TABLE IF NOT EXISTS table_name AS EXECUTE query;

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Andreas Karlsson <andreas(at)proxel(dot)se>
Cc: PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Add missing CREATE TABLE IF NOT EXISTS table_name AS EXECUTE query;
Date: 2019-02-17 23:49:50
Message-ID: 20190217234950.GC1864@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sun, Feb 17, 2019 at 03:31:05PM +0100, Andreas Karlsson wrote:
> Yeah, noticed the same thing myself while refactoring the CTAS code, but I
> guess the output could be like the current output for "EXPLAIN ANALYZE
> <CTAS> WITH NO DATA;", i.e. a top plan with "(never executed)" (see below
> for an example).

Yes, that matches my ideas on the matter (when excluding some
partitions at execution time for pruning something similar is used),
except that I would have used "(never executed as relation exists)" or
similar so as it is possible to make the difference between a relation
not created and no data inserted if using a CTAS IF NOT EXISTS with NO
DATA.

> The main thing which bothers me right now about my refactoring is how
> different the code paths for CTAS and EXPLAIN ANALYZE CTAS are, which leads
> to weirdness like this. I wonder if we cannot make them share more code e.g.
> by having ExplainOneUtility() call into some function in createas.c.

I think that we are on the same page here. The code path creating the
CTAS relation includes the if_not_exists check which should be used by
EXPLAIN, EXECUTE and normal CTAS, and return an ObjectAddress maybe
invalid if the relation has not been created. I have not looked in
details, but it seems that we would need to pass down if_not_exists to
the IntoClause.

> Maybe I should give it a shot and then start a new thread for the
> refactoring once I have looked more into this.

Thanks! That's not something which would get back-patched, and the
new APIs can be designed more carefully.
--
Michael

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2019-02-17 23:53:41 Re: pg_dump multi VALUES INSERT
Previous Message Tom Lane 2019-02-17 23:49:04 Re: Ryu floating point output patch