Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgresql - CREATE TABLE SYNTAX ERROR USING LIKE -

Tags:

postgresql

I'm trying to create a temp table from a parent table:

This is the code that I execute with pgAdmin III (or by JDBC in Java):

CREATE TEMP TABLE table1_tmp LIKE table1 INCLUDING DEFAULTS; 

And the error I received is:

[WARNING  ] CREATE TEMP TABLE table1_tmp LIKE table1 INCLUDING DEFAULTS         ERROR:  syntax error at or near «LIKE»         LÍNEA 1: CREATE TEMP TABLE table1_tmp LIKE table1 INCLUDING DEFAULTS                                               ^ 

Reading postgresql 8.4 documentation, create tables using this, its very easy, but I don't understand where is the syntax problem.

like image 809
jzafrilla Avatar asked Feb 02 '11 12:02

jzafrilla


1 Answers

You need to put the like in to parens like

CREATE TEMP TABLE table1_tmp ( LIKE table1 INCLUDING DEFAULTS ) ; 

This is not obvious from the docs if you don't count parens 1:1

like image 193
Heiko Rupp Avatar answered Oct 08 '22 01:10

Heiko Rupp