473,394 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Unbelievable SQL0811N on scalar subselect

Hello.
v8.2.1

Anybody can try this:
----------
--base table
DECLARE GLOBAL TEMPORARY TABLE SESSION.T (I INT)
with replace on commit preserve rows;
--insert 10 rows into table t
INSERT INTO SESSION.T
with t(v) as
(
VALUES (1) union all select v+1 from t where v<10
)
select * from t;

--reference
DECLARE GLOBAL TEMPORARY TABLE SESSION.R
(IND INT GENERATED ALWAYS AS IDENTITY, I INT)
with replace on commit preserve rows;
--insert 10 rows into table r
INSERT INTO SESSION.R (I)
with t(v) as
(
VALUES (1) union all select v+1 from t where v<10
)
select * from t;

--try to update table t
--by random value from reference
update SESSION.T
set I=
(
select IND from session.r where IND=1+round(rand()*(10-1), 0)
);
----------
After last statement I get SQL0811N.
But it's impossible I think because SESSION.R.IND is GENERATED ALWAYS
AS IDENTITY.
How it could be?

Sincerely,
Mark B.

Oct 27 '06 #1
2 4146
4.****@mail.ru wrote:
update SESSION.T
set I=
(
select IND from session.r where IND=1+round(rand()*(10-1), 0)
);
----------
After last statement I get SQL0811N.
But it's impossible I think because SESSION.R.IND is GENERATED ALWAYS
AS IDENTITY.
How it could be?
Simple:

one row (IND = 4) in SESSION.R

WHERE ind = 1 + ROUND(RAND() * 9, 0 )

-RAND() = 3
-WHERE 4 = 1 + 3
-true; row qualifies

some other row (IND = 2) in SESSION.R

WHERE ind = 1 + ROUND(RAND() * 9, 0 )

-RAND() = 1
-WHERE 2 = 1 + 1
-true; row qualifies

The thing is that the RAND() function is evaluated for each row in
SESSION.R. You don't reuse the same randomized value for all the rows.
Thus, multiple rows can satisfy the subselect, making it non-scalar.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Oct 27 '06 #2
I've understood.
Thanks, Knut.
Simple:

one row (IND = 4) in SESSION.R

WHERE ind = 1 + ROUND(RAND() * 9, 0 )

-RAND() = 3
-WHERE 4 = 1 + 3
-true; row qualifies

some other row (IND = 2) in SESSION.R

WHERE ind = 1 + ROUND(RAND() * 9, 0 )

-RAND() = 1
-WHERE 2 = 1 + 1
-true; row qualifies

The thing is that the RAND() function is evaluated for each row in
SESSION.R. You don't reuse the same randomized value for all the rows.
Thus, multiple rows can satisfy the subselect, making it non-scalar.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Oct 27 '06 #3

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

Similar topics

0
by: limbert | last post by:
------=_NextPart_000_0001_01C34D7B.DFBF53C0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi, =20 I was reading the manual and it said that...
6
by: Greg Stark | last post by:
So I have a query in which some of the select values are subqueries. The subqueries are aggregates so I don't want to turn this into a join, it would become too complex and postgres would have...
3
by: Neil Zanella | last post by:
Hello, I would like to ask the about the following... PostgreSQL allows tables resulting from subselects to be renamed with an optional AS keyword whereas Oracle 9 will report an error...
4
by: James | last post by:
I have a performance problem with the following query and variations on the subselect. The EXISTS version of the first example will complete in ~10 minutes. The NOT logic in both the examples...
4
by: dtwalter | last post by:
Is it possible to ORDER BY a SubSelect? I don't see why it wouldn't be, but I'm having some trouble. Hopefully it's just a simple error in syntax and somebody can tell me. Here's what I'm trying...
1
by: Marco Lazzeri | last post by:
I'd like to reference values returned by a subselect in the same SELECT query. Example: SELECT id, ( SELECT COUNT(*) FROM second ) AS value_to_reference, ( value_to_reference + 1 ) AS...
4
by: Chris Kratz | last post by:
Hello all, We have run into what appears to be a problem with rules and subselects in postgres 7.4.1. We have boiled it down to the following test case. If anyone has any thoughts as to why...
6
by: Sebastien | last post by:
I have the following statement which I run successfully in... 1 hour 10 minutes. SELECT a.tsgicd as ACCT_ID, a.tsa5cd as SEC_ID, CASE WHEN (SUBSTRING(a.tsgicd, 6, 1) = 'R' or...
1
by: mohit1286 | last post by:
my stored procedure in db2 is---> create procedure temp_bill(in UPC_cd character(6)) language sql begin declare prod_cd character(8);declare prod_desc varchar(30);declare discount...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.