473,473 Members | 1,484 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Order by not working on select into GTT

I am executing the following code below. When we execute this on our
TEST system (Redhat 4.0, DB2 V8.2 FP11) the rows are returned in order
of dollar_range_from. We just moved our Production system from V7.2
(Redhat 2.1) to a
RedHat 4.0 64-bit/Db2 V8.2 64-bit FP14 enviromnment and now the below
code returns the rows out of order from the temp table even though
they were inserted with an order by.

DECLARE GLOBAL TEMPORARY TABLE session.TEMPTABLE ( dollar_range_from
DECIMAL(15,2), dollar_range_to DECIMAL(15,2) )
ON COMMIT PRESERVE ROWS NOT LOGGED ;

insert into session.TEMPTABLE
SELECT from_amount as dollar_range_from, to_amount as
dollar_range_to FROM prodsys.dollar_range_bands WHERE
dollar_range_type = 'T' AND report_ids = 'REPORT3' AND coverage_type =
'99' OrDER BY by dollar_range_from;
select * from session.temptable;

Mar 9 '07 #1
5 3711
ebsch94 wrote:
I am executing the following code below. When we execute this on our
TEST system (Redhat 4.0, DB2 V8.2 FP11) the rows are returned in order
of dollar_range_from. We just moved our Production system from V7.2
(Redhat 2.1) to a
RedHat 4.0 64-bit/Db2 V8.2 64-bit FP14 enviromnment and now the below
code returns the rows out of order from the temp table even though
they were inserted with an order by.
The DBMS (in this case db2) will retrive rows in what order it finds
most appropiate for the moment, unless you explicitly specify an order.
This is how it is supposed to work. I'm a bit surprised that you can do
insert with an order by, since it is has no meaning. You should move
the "order by" so that it becomes part of the select instead of the insert

/Lennart
>

DECLARE GLOBAL TEMPORARY TABLE session.TEMPTABLE ( dollar_range_from
DECIMAL(15,2), dollar_range_to DECIMAL(15,2) )
ON COMMIT PRESERVE ROWS NOT LOGGED ;

insert into session.TEMPTABLE
SELECT from_amount as dollar_range_from, to_amount as
dollar_range_to FROM prodsys.dollar_range_bands WHERE
dollar_range_type = 'T' AND report_ids = 'REPORT3' AND coverage_type =
'99' OrDER BY by dollar_range_from;
select * from session.temptable;
Mar 9 '07 #2
On Mar 9, 3:10 pm, Lennart <erik.lennart.jons...@gmail.comwrote:
ebsch94 wrote:
I am executing the following code below. When we execute this on our
TEST system (Redhat 4.0, DB2 V8.2 FP11) the rows are returned in order
of dollar_range_from. We just moved our Production system from V7.2
(Redhat 2.1) to a
RedHat 4.0 64-bit/Db2 V8.2 64-bit FP14 enviromnment and now the below
code returns the rows out of order from the temp table even though
they were inserted with an order by.

The DBMS (in this case db2) will retrive rows in what order it finds
most appropiate for the moment, unless you explicitly specify an order.
This is how it is supposed to work. I'm a bit surprised that you can do
insert with an order by, since it is has no meaning. You should move
the "order by" so that it becomes part of the select instead of the insert

/Lennart


DECLARE GLOBAL TEMPORARY TABLE session.TEMPTABLE ( dollar_range_from
DECIMAL(15,2), dollar_range_to DECIMAL(15,2) )
ON COMMIT PRESERVE ROWS NOT LOGGED ;
insert into session.TEMPTABLE
SELECT from_amount as dollar_range_from, to_amount as
dollar_range_to FROM prodsys.dollar_range_bands WHERE
dollar_range_type = 'T' AND report_ids = 'REPORT3' AND coverage_type =
'99' OrDER BY by dollar_range_from;
select * from session.temptable;- Hide quoted text -

- Show quoted text -
It seems that in our QA system, and prior production system these rows
were returned in order of dollar_range_from, and unfortunately our
developer does other operations before the final select that depends
on those rows being in order. He is convinced something is wrong
because it behaves differently in our new production system.
Mar 9 '07 #3
ebsch94 wrote:
[...]
>
It seems that in our QA system, and prior production system these rows
were returned in order of dollar_range_from, and unfortunately our
developer does other operations before the final select that depends
on those rows being in order.
You've lost me here. How are the rows suposed to be in any order before
you retrieved them?
He is convinced something is wrong
because it behaves differently in our new production system.
A table is a set (actually a bag in sql), Therefor unordered by
definition. If rows where retrieved in a particular order before, it
could depend of a lot of things (luck, internal implementation, etc).
However, you should never ever expect them to do so (as you have noticed
by now).

If it where any other way you should be able to find a reference or two
that says that it is safe to assume that the rows are returned in a
certain order without using an order by. I dont think you will find one.

/Lennart
Mar 9 '07 #4
ebsch94 wrote:
[...]
>
It seems that in our QA system, and prior production system these rows
were returned in order of dollar_range_from, and unfortunately our
developer does other operations before the final select that depends
on those rows being in order.
You've lost me here. How are the rows suposed to be in any order before
you retrieved them?
He is convinced something is wrong
because it behaves differently in our new production system.
A table is a set (actually a bag in sql), Therefor unordered by
definition. If rows where retrieved in a particular order before, it
could depend of a lot of things (luck, internal implementation, etc).
However, you should never ever expect them to do so (as you have noticed
by now).

If it where any other way you should be able to find a reference or two
that says that it is safe to assume that the rows are returned in a
certain order without using an order by. I dont think you will find one.

/Lennart
Mar 9 '07 #5
Lennart wrote:
If it where any other way you should be able to find a reference or two
that says that it is safe to assume that the rows are returned in a
certain order without using an order by. I dont think you will find one.
If you do, please report it because that's a bug.

--
Knut Stolze
DB2 z/OS Admin Enablement
IBM Germany
Mar 12 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Xenophobe | last post by:
I have successfully converted the ASP code included in the following article to PHP: http://www.4guysfromrolla.com/webtech/040100-1.shtml As described the high and low latitudes and longitudes...
2
by: Paulo Andre Ortega Ribeiro | last post by:
I have a Microsoft SQL Server 7.0. I wrote a sql command that creates a temporary table with a ORDER BY clause. When a execute a SELECT on this temporary table sometimes the result is ok, but...
1
by: Tom Schindl | last post by:
Hi, the following Statement worked on MySQL 4.0 but after upgrading to 4.1.12 on win32 the order is not working any more. Is this a known problem or is our SQL simply not useable on 4.1 or is...
4
by: dave | last post by:
hi all, hope someone can help.... i'm having trouble calling an SP where the ORDER BY operator is specified as a parameter when the SP is called my SP is..... CREATE PROCEDURE...
2
by: S. van Beek | last post by:
Dear reader, The following code delivers a wild card in the result of the query. But the ORDER BY is not longer working.
104
by: Beowulf | last post by:
I have the view below and if I use vwRouteReference as the rowsource for a combo box in an MS Access form or run "SELECT * FROM vwRouteReference" in SQL Query Analyzer, the rows don't come through...
6
by: weetat.yeo | last post by:
Hi all , I have sql statement below , SELECT serial_no,host_name,chasis_model,chasis_flash_size,chasis_dram_size,...
3
by: =?Utf-8?B?VmFuZXNzYQ==?= | last post by:
Here is my loop and it runs fine: ---------------------------------------------------- sSQL = "SELECT * FROM STORE_ITEMS" Set DataRec = DB.execute(sSQL) if not DataRec.EOF then do while not...
4
by: fluff | last post by:
Hello. I want to display some data from a database in a certain order. I have a table with columns A, B, Date. I want to display the records that have data in column A first and I want those...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.