Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

OUTER UNION

Question posted by: Troels Arvin (Guest) on August 5th, 2008 09:25 AM
Hello,

While looking into a particular SQL statement which seemed to put the
database under pressure, I found the following construct which is new to
me:

SELECT ...
FROM ...
OUTER UNION
SELECT ...
FROM ...

The statement was seen in the "Dynamic SQL statement text" part of "GET
SNAPSHOT FOR APPLICATION". In other words: The construct was accepted by
DB2. OUTER UNION doesn't seem to part of the SQL standard, and I can't
find documentation for it in DB2's documentation. Is this a documentation
defect, or is it simply me who's not good enough at searching the docs?

(The statement was issued from a SAS script, probably part of a SAS "proc
sql" section. OUTER UNION is documented in SAS' docs. I want to make sure
that SAS and DB2 agree on what's going on.)

--
Regards,
Troels Arvin <troels@arvin.dk>
http://troels.arvin.dk/
Serge Rielau's Avatar
Serge Rielau
Guest
n/a Posts
August 5th, 2008
10:45 AM
#2

Re: OUTER UNION
Troels Arvin wrote:
Quote:
Hello,
>
While looking into a particular SQL statement which seemed to put the
database under pressure, I found the following construct which is new to
me:
>
SELECT ...
FROM ...
OUTER UNION
SELECT ...
FROM ...
>
The statement was seen in the "Dynamic SQL statement text" part of "GET
SNAPSHOT FOR APPLICATION". In other words: The construct was accepted by
DB2. OUTER UNION doesn't seem to part of the SQL standard, and I can't
find documentation for it in DB2's documentation. Is this a documentation
defect, or is it simply me who's not good enough at searching the docs?
>
(The statement was issued from a SAS script, probably part of a SAS "proc
sql" section. OUTER UNION is documented in SAS' docs. I want to make sure
that SAS and DB2 agree on what's going on.)
>

db2 =connect to test;

Database Connection Information

Database server = DB2/NT 9.X.0
SQL authorization ID = SRIELAU
Local database alias = TEST

db2 =values 1 outer union values 1;
SQL0104N An unexpected token "outer" was found following "values 1 ".
Expected tokens may include: "<space>". SQLSTATE=42601
db2 =values 1 union values 1;

1
-----------
1

1 record(s) selected.


Which platform are you on? I have never heard of it. What would be it's
semantics?

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

Troels Arvin's Avatar
Troels Arvin
Guest
n/a Posts
August 5th, 2008
11:15 AM
#3

Re: OUTER UNION
Serge Rielau wrote:
Quote:
db2 =values 1 outer union values 1; SQL0104N An unexpected token
"outer" was found following "values 1 ". Expected tokens may include:
"<space>". SQLSTATE=42601 db2 =values 1 union values 1;
>
1
-----------
1
>
1 record(s) selected.
>
>
Which platform are you on?


DB2 v. 8 on AIX and DB2 v. 9.5 on Linux. On these platforms, your test
with VALUES ... VALUES also results in an error. But if I use real test
tables, "outer union" is accepted. It seems DB2 simply ignores the "outer"
word.

Quote:
I have never heard of it. What would be it's semantics?


http://v8doc.sas.com/sashtml/proc/zueryexp.htm has some examples of it. If
my reading of SAS' docs is right, the semantics of SAS' OUTER UNION is
certainly not to simply ignore the OUTER word. SAS is surely being strange
regarding this (as it is with heaps of other subjects), but so is DB2: Why
doesn't it protest?

--
Regards,
Troels Arvin <troels@arvin.dk>
http://troels.arvin.dk/

Serge Rielau's Avatar
Serge Rielau
Guest
n/a Posts
August 5th, 2008
02:25 PM
#4

Re: OUTER UNION
Troels Arvin wrote:
Quote:
Serge Rielau wrote:
Quote:
>db2 =values 1 outer union values 1; SQL0104N An unexpected token
>"outer" was found following "values 1 ". Expected tokens may include:
>"<space>". SQLSTATE=42601 db2 =values 1 union values 1;
>>
>1
>-----------
> 1
>>
> 1 record(s) selected.
>>
>>
>Which platform are you on?

>
DB2 v. 8 on AIX and DB2 v. 9.5 on Linux. On these platforms, your test
with VALUES ... VALUES also results in an error. But if I use real test
tables, "outer union" is accepted. It seems DB2 simply ignores the "outer"
word.
>
>
Quote:
>I have never heard of it. What would be it's semantics?

>
http://v8doc.sas.com/sashtml/proc/zueryexp.htm has some examples of it. If
my reading of SAS' docs is right, the semantics of SAS' OUTER UNION is
certainly not to simply ignore the OUTER word. SAS is surely being strange
regarding this (as it is with heaps of other subjects), but so is DB2: Why
doesn't it protest?
>

Oh!, Ohh!

SELECT outer.c1 FROM T OUTER UNION VALUES 1;

:-)

Cheers
Serge



--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

--CELKO--'s Avatar
--CELKO--
Guest
n/a Posts
August 6th, 2008
09:25 PM
#5

Re: OUTER UNION
The OUTER UNION is part of the infixed JOINs we define4d in SQL-99.
Nobody uses it,but it was easy to define, so it got into the
Standards. It can stick two totally unrelated tables together
blindly.

http://www2.sas.com/proceedings/sugi31/242-31.pdf

Troels Arvin's Avatar
Troels Arvin
Guest
n/a Posts
August 7th, 2008
12:25 PM
#6

Re: OUTER UNION
--CELKO-- wrote:
Quote:
The OUTER UNION is part of the infixed JOINs we define4d in SQL-99.


I can't find it in the draft for SQL:200n. Where in the SQL:1999 standard
is it mentioned?

--
Regards,
Troels Arvin <troels@arvin.dk>
http://troels.arvin.dk/

Serge Rielau's Avatar
Serge Rielau
Guest
n/a Posts
August 7th, 2008
01:35 PM
#7

Re: OUTER UNION
Troels Arvin wrote:
Quote:
--CELKO-- wrote:
Quote:
>The OUTER UNION is part of the infixed JOINs we define4d in SQL-99.

>
I can't find it in the draft for SQL:200n. Where in the SQL:1999 standard
is it mentioned?
>

Troels,

Did you see my post? DB2 interpretes the OUTER as a table alias.
T AS OUTER.

Cheers
Serge



--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

Troels Arvin's Avatar
Troels Arvin
Guest
n/a Posts
August 7th, 2008
09:35 PM
#8

Re: OUTER UNION
Serge Rielau wrote:
Quote:
Oh!, Ohh!
>
SELECT outer.c1 FROM T OUTER UNION VALUES 1;


This was what I thought initially, as well (potentially very much
different from what the user expects after reading SAS' docs). But I've
seen OUTER UNION work with three different tables:

SELECT ...
FROM ...
OUTER UNION
SELECT ...
FROM ...
OUTER UNION
SELECT ...
FROM ...

Would DB2 allow re-use of table aliases?

--
Regards,
Troels Arvin <troels@arvin.dk>
http://troels.arvin.dk/

Serge Rielau's Avatar
Serge Rielau
Guest
n/a Posts
August 8th, 2008
01:55 AM
#9

Re: OUTER UNION
Troels Arvin wrote:
Quote:
Would DB2 allow re-use of table aliases?

Yes, just try:
SELECT * FROM T AS X
UNION
SELECT * FROM T AS X
UNION
SELECT * FROM T AS X



--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

Lennart's Avatar
Lennart
Guest
n/a Posts
August 8th, 2008
08:45 AM
#10

Re: OUTER UNION
On Aug 7, 2:19*pm, Troels Arvin <tro...@arvin.dkwrote:
Quote:
--CELKO-- wrote:
Quote:
The OUTER UNION is part of the infixed JOINs we define4d in SQL-99.

>
I can't find it in the draft for SQL:200n. Where in the SQL:1999 standard
is it mentioned?
>


I cant find it either and Mimers SQL Validator (http://
developer.mimer.com/validator/) doesn't recognize the construct.
CORRESPONDING is a reserved word though, but it where reserved back in
SQL92.


/Lennart

--CELKO--'s Avatar
--CELKO--
Guest
n/a Posts
August 8th, 2008
04:15 PM
#11

Re: OUTER UNION
My bad! It is UNION JOIN in SQL-92, section 7.5


 
Not the answer you were looking for? Post your question . . .
189,873 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors