create table if not exists xx AS select ...

Started by Daniel Caldeweyherabout 11 years ago3 messagesgeneral
Jump to latest
#1Daniel Caldeweyher
daniel.caldeweyher@pricefinder.com.au

Hi All,

I am not entirely sure if this is a bug (fails on 9.3 and 9.4) or working
as intended:

create table if not exists test (
foo boolean
);

create table if not exists test2 as
select * from test where 1=0;
/*
ERROR: syntax error at or near "as"
LINE 1: create table if not exists test2 as
*/

create table test2 as
select * from test where 1=0;

Thanks

Daniel

#2Michael Paquier
michael@paquier.xyz
In reply to: Daniel Caldeweyher (#1)
Re: create table if not exists xx AS select ...

On Mon, Mar 23, 2015 at 10:28 AM, Daniel Caldeweyher
<daniel.caldeweyher@pricefinder.com.au> wrote:

I am not entirely sure if this is a bug (fails on 9.3 and 9.4) or working as
intended:
[...]
create table test2 as
select * from test where 1=0;

This works as intended, CREATE TABLE AS does not support IF NOT EXISTS
in 9.4 and 9.3:
http://www.postgresql.org/docs/9.3/static/sql-createtableas.html
http://www.postgresql.org/docs/9.4/static/sql-createtableas.html
But it does in 9.5 and onwards:
http://www.postgresql.org/docs/devel/static/sql-createtableas.html
Regards,
--
Michael

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#3Daniel Caldeweyher
daniel.caldeweyher@pricefinder.com.au
In reply to: Michael Paquier (#2)
Re: create table if not exists xx AS select ...

Thanks Michael,

I suppose I should have checked the docs for CREATE TABLE AS and not
just CREATE
TABLE :)

Regards,
Daniel

On Mon, Mar 23, 2015 at 11:41 AM, Michael Paquier <michael.paquier@gmail.com

Show quoted text

wrote:

On Mon, Mar 23, 2015 at 10:28 AM, Daniel Caldeweyher
<daniel.caldeweyher@pricefinder.com.au> wrote:

I am not entirely sure if this is a bug (fails on 9.3 and 9.4) or

working as

intended:
[...]
create table test2 as
select * from test where 1=0;

This works as intended, CREATE TABLE AS does not support IF NOT EXISTS
in 9.4 and 9.3:
http://www.postgresql.org/docs/9.3/static/sql-createtableas.html
http://www.postgresql.org/docs/9.4/static/sql-createtableas.html
But it does in 9.5 and onwards:
http://www.postgresql.org/docs/devel/static/sql-createtableas.html
Regards,
--
Michael

Attachments:

image011.pngimage/png; name=image011.pngDownload
image012.pngimage/png; name=image012.pngDownload
image007.pngimage/png; name=image007.pngDownload
image008.pngimage/png; name=image008.pngDownload
image009.pngimage/png; name=image009.pngDownload