Quantcast

[SQL] SQL command Error: "create table ... Like parentTable including defaults"

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[SQL] SQL command Error: "create table ... Like parentTable including defaults"

Ying Lu
Greetings,

I have a simple question about SQL command :

create table tableName1 LIKE parentTable   INCLUDING defaults ;


I was trying to create table "tableName1" with the same structure as
"parentTable" without any data. I got a syntax error:
'syntax error at or near "like" ... '

I guess there must be something wrong with my sql command, could
somebody help?

Thanks a lot,
Emi

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
      joining column's datatypes do not match
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [SQL] SQL command Error: "create table ... Like parentTable

Bricklen Anderson
Ying Lu wrote:

> Greetings,
>
> I have a simple question about SQL command :
>
> create table tableName1 LIKE parentTable   INCLUDING defaults ;
>
>
> I was trying to create table "tableName1" with the same structure as
> "parentTable" without any data. I got a syntax error: 'syntax error at
> or near "like" ... '
>
> I guess there must be something wrong with my sql command, could
> somebody help?
>
> Thanks a lot,
> Emi

I've never used the "LIKE..INCLUDING" clause before so I can't comment on that,
but as an alternative, you could try a CTAS:
create table tableName1 as select * from parentTable where 1=0; (will not get
the rows, just the structure).


Cheers,

Bricklen
--
_______________________________

This e-mail may be privileged and/or confidential, and the sender does
not waive any related rights and obligations. Any distribution, use or
copying of this e-mail or the information it contains by other than an
intended recipient is unauthorized. If you received this e-mail in
error, please advise me (by return e-mail or otherwise) immediately.
_______________________________

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
      subscribe-nomail command to [hidden email] so that your
      message can get through to the mailing list cleanly
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [SQL] SQL command Error: "create table ... Like parentTable including defaults"

Michael Fuhr
In reply to this post by Ying Lu
On Fri, May 27, 2005 at 11:48:39AM -0400, Ying Lu wrote:
>
> create table tableName1 LIKE parentTable   INCLUDING defaults ;
>
> I was trying to create table "tableName1" with the same structure as
> "parentTable" without any data. I got a syntax error:
> 'syntax error at or near "like" ... '

The CREATE TABLE documentation shows that LIKE should be in parentheses:

CREATE TABLE tableName1 (LIKE parentTable INCLUDING DEFAULTS);

http://www.postgresql.org/docs/8.0/interactive/sql-createtable.html

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Loading...