Thread: CREATE TABLE AS and ORDER BY

CREATE TABLE AS and ORDER BY

From
Joy Chuang
Date:
Hi,

I tried to use CREATE TABLE AS and ORDER BY.  The query is as followed:

create table freshhr21 as
select e.studentid, u.hoursxfer
from enrollmentstatus e, undergradclass u
where e.studentid = u.studentid and e.classtd = '1'
order by u.hoursxfer

But, it returns error message "ERROR:  parser: parse error at or near
"order"".  Does "create table as" support "order by" inside of it?

I am using PostgreSQL 6.5.3.

Thank you.

Joy Chuang



Re: CREATE TABLE AS and ORDER BY

From
Tom Lane
Date:
Joy Chuang <hxc0850@omega.uta.edu> writes:
> But, it returns error message "ERROR:  parser: parse error at or near
> "order"".  Does "create table as" support "order by" inside of it?

Evidently not.

> I am using PostgreSQL 6.5.3.

It seems to work in 7.0 and later.
        regards, tom lane


Re: CREATE TABLE AS and ORDER BY

From
Jie Liang
Date:
Hey,

Try:

select e.studentid, u.hoursxfer into freshhr21
from enrollmentstatus e, undergradclass u
where e.studentid = u.studentid and e.classtd = '1'
order by u.hoursxfer


Jie LIANG

Internet Products Inc.

10350 Science Center Drive
Suite 100, San Diego, CA 92121
Office:(858)320-4873

jliang@ipinc.com
www.ipinc.com

On Mon, 5 Feb 2001, Joy Chuang wrote:

> Hi,
> 
> I tried to use CREATE TABLE AS and ORDER BY.  The query is as followed:
> 
> create table freshhr21 as
> select e.studentid, u.hoursxfer
> from enrollmentstatus e, undergradclass u
> where e.studentid = u.studentid and e.classtd = '1'
> order by u.hoursxfer
> 
> But, it returns error message "ERROR:  parser: parse error at or near
> "order"".  Does "create table as" support "order by" inside of it?
> 
> I am using PostgreSQL 6.5.3.
> 
> Thank you.
> 
> Joy Chuang
> 



Re: CREATE TABLE AS and ORDER BY

From
"CM"
Date:
"Joy Chuang" <hxc0850@omega.uta.edu> wrote in message
news:3A7F5AF9.B23DF42F@omega.uta.edu...
> Hi,
>
> I tried to use CREATE TABLE AS and ORDER BY.  The query is as followed:
>
> create table freshhr21 as
> select e.studentid, u.hoursxfer
> from enrollmentstatus e, undergradclass u
> where e.studentid = u.studentid and e.classtd = '1'
> order by u.hoursxfer
>
> But, it returns error message "ERROR:  parser: parse error at or near
> "order"".  Does "create table as" support "order by" inside of it?
>
> I am using PostgreSQL 6.5.3.

When you CREATE TABLEs you don't say anything about ordering.  I should say
it doesn't matter what the order is.  When you SELECT from the table you can
use ORDER BY.