pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andreas Karlsson <andreas@proxel.se>
To: PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Subject: Add missing CREATE TABLE IF NOT EXISTS table_name AS EXECUTE query;
Date: Wed, 6 Feb 2019 03:20:41 +0100
Message-ID: <2ddcc188-e37c-a0be-32bf-a56b07c3559e@proxel.se> (raw)

Hi,

The first example below works while the second one is a syntax error 
despite that the documentation 
(https://www.postgresql.org/docs/11/sql-createtableas.html) makes it 
seem like both should be valid. I do not see any reason to not support 
CTAS with both IF NOT EXISTS and EXECUTE at the same time so i am 
guessing that this was an oversight.

I have attached a patch which fixes this. What do you think? Should I 
add a new test case for this or is the change simple enough to not 
require any new test?

# CREATE TABLE IF NOT EXISTS a AS SELECT 1;
SELECT 1

# PREPARE q AS SELECT 1;
PREPARE
Time: 0.209 ms
foo=# CREATE TABLE IF NOT EXISTS a AS EXECUTE q;
ERROR:  syntax error at or near "EXECUTE"
LINE 1: CREATE TABLE IF NOT EXISTS a AS EXECUTE q;
                                         ^

Andreas

Attachments:

  [application/sql] ctas-exec-ifne-v1.sql (1.5K, ../2ddcc188-e37c-a0be-32bf-a56b07c3559e@proxel.se/2-ctas-exec-ifne-v1.sql)
  download

view thread (10+ messages)  latest in thread

Message-ID: <2ddcc188-e37c-a0be-32bf-a56b07c3559e@proxel.se>
Permalink:  ../2ddcc188-e37c-a0be-32bf-a56b07c3559e@proxel.se/
Also on:    postgresql.org/message-id/2ddcc188-e37c-a0be-32bf-a56b07c3559e@proxel.se

 · 

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: pgsql-hackers@postgresql.org
  Cc: andreas@proxel.se, pgsql-hackers@lists.postgresql.org
  Subject: Re: Add missing CREATE TABLE IF NOT EXISTS table_name AS EXECUTE query;
  In-Reply-To: <2ddcc188-e37c-a0be-32bf-a56b07c3559e@proxel.se>

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

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