Thread

  1. INSERT/SELECT with ORDER BY

    Bob Rivoir <rhr2@psu.edu> — 2000-08-18T02:32:41Z

    ============================================================================
    
                            POSTGRESQL BUG REPORT TEMPLATE
    ============================================================================
    
    
    
    Your name  :  Bob Rivoir
    Your email address : rhr2@psu.edu
    
    
    System Configuration
    ---------------------
      Architecture (example: Intel Pentium)   : AMD Athlon
    
      Operating System (example: Linux 2.0.26 ELF)  : OpenLinux eDesktop 2.4
    
      PostgreSQL version (example: PostgreSQL-7.0):   PostgreSQL-7.0.2
    
      Compiler used (example:  gcc 2.8.0)  : gcc egcs-1.1.2 release
    
    
    Please enter a FULL description of your problem:
    ------------------------------------------------
    I got the following error message when I tried to do an INSERT using
    SELECT ... ORDER BY:
    
    ERROR:  ORDER BY is not allowed in INSERT/SELECT
    
    
    Please describe a way to repeat the problem.   Please try to provide a
    concise reproducible example, if at all possible:
    ----------------------------------------------------------------------
    
    
    
    
    
    If you know how this problem might be fixed, list the solution below:
    ---------------------------------------------------------------------
    
    
    
    
    
  2. Re: INSERT/SELECT with ORDER BY

    Stephan Szabo <sszabo@megazone23.bigpanda.com> — 2000-08-18T18:23:39Z

    Unless I'm horribly misreading the spec, this is correct.  
    ORDER BY is used in reference to cursor definitions and
    direct select statements, but is not part of query expressions
    which is what the INSERT INTO references.
    
             <insert statement> ::=
                  INSERT INTO <table name>
                    <insert columns and source>
    
             <insert columns and source> ::=
                    [ <left paren> <insert column list> <right paren> ]
                  <query expression>
                  | DEFAULT VALUES
    
             <insert column list> ::= <column name list>
    
    But, this may be a useful extension to allow, at least with the
    existance of LIMIT.
    
    Stephan Szabo
    sszabo@bigpanda.com
    
    On Thu, 17 Aug 2000, Bob Rivoir wrote:
    > 
    > Please enter a FULL description of your problem:
    > ------------------------------------------------
    > I got the following error message when I tried to do an INSERT using
    > SELECT ... ORDER BY:
    > 
    > ERROR:  ORDER BY is not allowed in INSERT/SELECT
    
    
    
    
  3. Re: INSERT/SELECT with ORDER BY

    Bruce Momjian <pgman@candle.pha.pa.us> — 2000-10-12T19:00:36Z

    > 
    > Unless I'm horribly misreading the spec, this is correct.  
    > ORDER BY is used in reference to cursor definitions and
    > direct select statements, but is not part of query expressions
    > which is what the INSERT INTO references.
    > 
    >          <insert statement> ::=
    >               INSERT INTO <table name>
    >                 <insert columns and source>
    > 
    >          <insert columns and source> ::=
    >                 [ <left paren> <insert column list> <right paren> ]
    >               <query expression>
    >               | DEFAULT VALUES
    > 
    >          <insert column list> ::= <column name list>
    > 
    > But, this may be a useful extension to allow, at least with the
    > existance of LIMIT.
    
    Yes, added to TODO.
    
    -- 
      Bruce Momjian                        |  http://candle.pha.pa.us
      pgman@candle.pha.pa.us               |  (610) 853-3000
      +  If your life is a hard drive,     |  830 Blythe Avenue
      +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
    
    
  4. Re: INSERT/SELECT with ORDER BY

    Dirk Lutzebäck <lutzeb@aeccom.com> — 2001-03-29T08:55:09Z

    Stephan Szabo writes:
     > 
     > Unless I'm horribly misreading the spec, this is correct.  
     > ORDER BY is used in reference to cursor definitions and
     > direct select statements, but is not part of query expressions
     > which is what the INSERT INTO references.
     > 
     >          <insert statement> ::=
     >               INSERT INTO <table name>
     >                 <insert columns and source>
     > 
     >          <insert columns and source> ::=
     >                 [ <left paren> <insert column list> <right paren> ]
     >               <query expression>
     >               | DEFAULT VALUES
     > 
     >          <insert column list> ::= <column name list>
     > 
     > But, this may be a useful extension to allow, at least with the
     > existance of LIMIT.
     > 
     > Stephan Szabo
     > sszabo@bigpanda.com
     > 
     > On Thu, 17 Aug 2000, Bob Rivoir wrote:
     > > 
     > > Please enter a FULL description of your problem:
     > > ------------------------------------------------
     > > I got the following error message when I tried to do an INSERT using
     > > SELECT ... ORDER BY:
     > > 
     > > ERROR:  ORDER BY is not allowed in INSERT/SELECT
    
    
    Is 7.1 able to do INSERT/SELECT with ORDER BY and LIMIT ?
    
    Dirk