[
https://issues.apache.org/jira/browse/DERBY-4?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12496230
]
Bernt M. Johnsen commented on DERBY-4:
--------------------------------------
I do not agree that we should implement this "feature". First of all, it is not
defined in the standard, and secondly it makes no sense wrt. SQL as a language.
SQL is basically a set language where the rows have no order. The ORDER BY
clause is used to order the rows when they are retrieved *from* the database.
Although the following SQL:
INSERT INTO T VALUES(1);
INSERT INTO T VALUES(2);
SELECT * FROM T;
In most databases will give you the result
1
2
But I've seen otherwise, and that's completely compliant with the standard. I
would say that any application based on the assumption that the INSERT order
has any influence on the result from a SELECT statement withou an ORDER BY
clause is buggy, so the tool Bryan is referring to should be fixed.
-1 To this "feature".
> "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
>
> 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.