You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by "Bryan Pendleton (JIRA)" <ji...@apache.org> on 2007/05/16 17:52:16 UTC

[jira] Updated: (DERBY-4) "order by" is not supported for "insert ... select"

     [ https://issues.apache.org/jira/browse/DERBY-4?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bryan Pendleton updated DERBY-4:
--------------------------------

    Attachment: insertOrderBy.diff

Attached is 'insertOrderBy.diff', a patch containing code changes,
but no new tests. This patch is *not* intended for commit, just as
a way to give us some concrete code to talk about. 

The patch adds a line to the parser to enable INSERT ... SELECT .. ORDER BY
and adds a bit of code to InsertNode to handle the OrderByList.

The code in InsertNode mimics the implementation in CursorNode;
perhaps there is some way to arrange for these two nodes to
share this code?

With the patch, derbyall and suites.All run clean, so I've made a first
attempt at verifying that this change doesn't break existing behaviors.
Also, I verified that a similar change to 10.2 can be made, if desired,
and also adds the new behavior without (obviously) breaking existing ones.

I'd love to keep the discussion going: either more general comments
on the underlying concepts of the feature, or specific comments about
the possible implementation in code. Thanks to all who have participated so far!



> "order by" is not supported for "insert ... select"
> ---------------------------------------------------
>
>                 Key: DERBY-4
>                 URL: https://issues.apache.org/jira/browse/DERBY-4
>             Project: Derby
>          Issue Type: New Feature
>          Components: SQL
>            Reporter: Christian d'Heureuse
>         Assigned To: Bryan Pendleton
>            Priority: Minor
>         Attachments: insertOrderBy.diff
>
>
> When filling a table with "insert ... select ...", "order by" cannot be specified.
> There is not method to copy a table sorted into another table (except using export/import). This would be useful to optimize performance for big tables, or to create identity values that are ascending (related to another column).
> Example:
> create table temp1 (
>    s varchar(10));
> insert into temp1 values 'x','a','c','b','a';
> create table temp2 (
>    i integer not null
>       generated always as identity
>       primary key,
>    s varchar(10));
> insert into temp2 (s)
>    select s from temp1 order by s;
> --> Error: "order by" is not allowed.
> -- trying to use "group by" instead of "oder by":
> insert into temp2 (s)
>    select s from temp1 group by s;
> select * from temp2;
> --> "group by" did not sort the table.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.