Re: greetings - Mailing list pgsql-sql

From Tom Lane
Subject Re: greetings
Date
Msg-id 15301.983052160@sss.pgh.pa.us
Whole thread Raw
In response to Re: greetings  (Ken Kline <ken@oldbs.com>)
List pgsql-sql
Ken Kline <ken@oldbs.com> writes:
> orginally what I wanted to do was this:

> INSERT INTO pledge_classes (semester, year)
> SELECT distinct pseason, pyear from load_bros
> WHERE  pyear is not null
> AND    pseason is not null
> order by pyear, pseason;

> however pgsql does not allow order by in an INSERT-SELECT statement

Three answers for the price of one ;-) :

1. Why are you trying to constrain the order in an INSERT in the first
place?  Tuple order in a table is meaningless under SQL semantics.

2. If you really feel you have to have that, you could rely on the
sorting done implicitly by DISTINCT:
INSERT INTO pledge_classes (year, semester)SELECT distinct pyear, pseason from load_brosWHERE  pyear is not nullAND
pseasonis not null;
 

3. 7.1 will allow you to use an ORDER BY here, pointless though it is.
        regards, tom lane


pgsql-sql by date:

Previous
From: Ken Kline
Date:
Subject: Re: greetings
Next
From: Ian Lance Taylor
Date:
Subject: Re: greetings