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

From: Andreas Karlsson <andreas(at)proxel(dot)se>
To: PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Add missing CREATE TABLE IF NOT EXISTS table_name AS EXECUTE query;
Date: 2019-02-06 02:20:41
Message-ID: 2ddcc188-e37c-a0be-32bf-a56b07c3559e@proxel.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

Attachment Content-Type Size
ctas-exec-ifne-v1.sql application/sql 1.5 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2019-02-06 03:11:53 Re: Bogus lateral-reference-propagation logic in create_lateral_join_info
Previous Message Andreas Karlsson 2019-02-06 02:11:33 Re: Feature: temporary materialized views