Go Back  IT Forums > Software > Informix
User Name
Password
Reply
 
Thread Tools Search this Thread Display Modes

select * from (select * from bob) and other easy stuff
  #1
Old 09-25-2006, 05:06 PM
internetuser
Junior Member


internetuser is offline
internetuser's Info
Join Date: Sep 2006
Posts: 8
Default select * from (select * from bob) and other easy stuff

New Informix user - coming from Oracle here. I'm baffled.

Why doesn't something simple like:

select * from (select * from bob)

work?

Also, if you do something like :

select upper(bob) jane from sometable
where jane = 'SMITH'
order by jane

it doesn't work either. It lets jane appear in the order by, but not
the where clause.

So how are you supposed to limit your results based off of aliased
(virtual) columns? This comes up for pretty much any time you use a
function against a column to get some result ("decode" is what I am
working with at the moment).

So far I find this flavour of SQL very limiting. Can someone help?

Thanks!
-sw

Reply With Quote
select * from (select * from bob) and other easy stuff
  #2
Old 09-25-2006, 06:48 PM
Adam Tauno Williams
Junior Member


Adam Tauno Williams is offline
Adam Tauno Williams's Info
Join Date: Jan 2005
Posts: 73
Default select * from (select * from bob) and other easy stuff

> Why doesn't something simple like:
Quote:
select * from (select * from bob) work?


SELECT * FROM TABLE(MULTISET(SELECT * FROM bob))
Quote:
Also, if you do something like : select upper(bob) jane from sometable where jane = 'SMITH' order by jane it doesn't work either. It lets jane appear in the order by, but not the where clause. So how are you supposed to limit your results based off of aliased (virtual) columns? This comes up for pretty much any time you use a function against a column to get some result ("decode" is what I am working with at the moment).



Reply With Quote
select * from (select * from bob) and other easy stuff
  #3
Old 09-26-2006, 06:56 AM
Fernando Nunes
Junior Member


Fernando Nunes is offline
Fernando Nunes's Info
Join Date: Sep 2006
Posts: 1
Default select * from (select * from bob) and other easy stuff


The inline table issue was already clarified.
Probably one of the next versions will allow the "usual" syntax.

The other questions:

.... WHERE UPPER(jane) = "SMITH"
ORDER BY 1;

You have to repeat the expression... it's probably annoying if you're
not used to it, but the background job is the same.
You can use numeric placeholders in ORDER BY and GROUP BY clauses.

Regards


internetuser wrote:
Quote:
New Informix user - coming from Oracle here. I'm baffled. Why doesn't something simple like: select * from (select * from bob) work? Also, if you do something like : select upper(bob) jane from sometable where jane = 'SMITH' order by jane it doesn't work either. It lets jane appear in the order by, but not the where clause. So how are you supposed to limit your results based off of aliased (virtual) columns? This comes up for pretty much any time you use a function against a column to get some result ("decode" is what I am working with at the moment). So far I find this flavour of SQL very limiting. Can someone help? Thanks! -sw


Reply With Quote
select * from (select * from bob) and other easy stuff
  #4
Old 09-26-2006, 09:25 AM
internetuser
Junior Member


internetuser is offline
internetuser's Info
Join Date: Sep 2006
Posts: 8
Default select * from (select * from bob) and other easy stuff

Ugh. How awkward. OK, thanks for the tips. I'm running into some issues
though (see below), which make things seem pretty bizarre to me.
Quote:
SELECT * FROM TABLE(MULTISET(SELECT * FROM bob))


It seems to be pretty useless though because using something like this:

select lwind_name,lw_type_cd from table(multiset(select * from
land_window))

I get a message:

[Error Code: -9930, SQL State: IX000]
Byte, Text, Serial or Serial8 datatypes in collection types not
allowed.

If you can't do something this basic because of a serial column, it's
rather lame and useless. It seems like Informix is going out of its way
to make me write multiple statements or use temp tables to avoid doing
things all at once like I've been doing with Oracle.
Quote:
The other questions: WHERE UPPER(jane) = "SMITH" ORDER BY 1; You have to repeat the expression... it's probably annoying if you're not used to it, but the background job is the same. You can use numeric placeholders in ORDER BY and GROUP BY clauses.


OK, so I have to do something like this:

select lwind_name, lower(lwind_name) winName
from land_window where lower(lwind_name) = 'coastal plain'

Well, it's more than just annoying. It makes the statements longer,
harder to read, and gives me twice as much to maintain, for no good
reason as far as I can tell. Is there really no better way?

There also seems to be some rather severe limitations here. Consider
the following code that works great with Oracle:

select
et_code,et_desc,case_type as ct_code,valid_case_type_desc_txt as
ct_desc
from notrust.valid_case_type vct,
(select e_type_code as ET_CODE,e_type_desc_txt as ET_DESC,
decode (e_type_code,'12A','265101','12B','265102','12C',' 265200',

'IL-SS','265202','POOL','265204','12CH8','265208','IL-S','265211','14H1',

'265301','14H2','265302','14H3','265303','14H5','2 65306','14H8','265308',

'14H6','265311','UGRT','262720','CGNF','262712','C GPD','262711','MH','262710',
'SCHL','262714','GPGT','262730','TNCGT','262713') as case_type
from notrust.e_type) acs
where acs.case_type = vct.valid_case_type_code and case_type is not
null

Trying to use this with Informix, we see right away that the long
decode statement has to be repeated in the where clause rather than
using "case_type", however, if you do that, you get the message:

[Error Code: -293, SQL State: IX000] I
IS [NOT] NULL predicate may be used only with simple columns.

So not only is repeating it annoying, it doesn't even work. On top of
that, you've got to move to this verbose method of using in-line tables
and hope that you're not using a serial value.

I guess I've got some work ahead of me to try to figure this stuff out.

Maybe I can get the database re-designed to avoid the use of serials.
Unfortunately, since the people who implement the database don't have
to write the code to use it, there is probably little chance of that
happening. These are the same people who decided to switch the
database from Oracle 10g to Informix 9 (v.9.4.0.UC3, zero chance of
getting a more recent version, ever) in the middle of my project, after
a lot of database code had already been written. I'm now in the process
of taking what was perfectly working code and make it work with
Informix. There seems to be a number of severe limitations and lack of
features that require one to have a very different mindset when writing
code for Informix. Can anyone shed some light?

Thanks!
-sw

Reply With Quote
select * from (select * from bob) and other easy stuff
  #5
Old 09-26-2006, 10:12 AM
Adam Tauno Williams
Junior Member


Adam Tauno Williams is offline
Adam Tauno Williams's Info
Join Date: Jan 2005
Posts: 73
Default select * from (select * from bob) and other easy stuff

Quote:
Ugh. How awkward. OK, thanks for the tips. I'm running into some issues though (see below), which make things seem pretty bizarre to me.
Quote:
SELECT * FROM TABLE(MULTISET(SELECT * FROM bob))
It seems to be pretty useless though because using something like this: select lwind_name,lw_type_cd from table(multiset(select * from land_window)) I get a message: [Error Code: -9930, SQL State: IX000] Byte, Text, Serial or Serial8 datatypes in collection types not allowed.


I don't know, this always made perfect sense to me. A "serial" data
type's serial-ness can't be preserved through a virtual table. But my
preference is that when something magick is happening it should be
required that it is explicitly stated (like turning a serial value into
an int value).
Quote:
If you can't do something this basic because of a serial column,


You can, you just need to cast it.

SELECT serial_key, other_value
FROM TABLE(MULTISET(SELECT serial_key::INT, other_value FROM booby));


Reply With Quote
select * from (select * from bob) and other easy stuff
  #6
Old 09-26-2006, 10:55 AM
internetuser
Junior Member


internetuser is offline
internetuser's Info
Join Date: Sep 2006
Posts: 8
Default select * from (select * from bob) and other easy stuff

Adam Tauno Williams wrote:
Quote:
I don't know, this always made perfect sense to me. A "serial" data type's serial-ness can't be preserved through a virtual table.


But while a "serial" may be something interesting before the number is
generated, once a value is actually generated and in the table, isn't
it in fact just a number, sitting there, ripe for the picking? For
example - if I do something like:

select myid,myid+50, v1,v2,v3,v4 from bob

I might get:

1,51,I am not impressed,true,true,true
50,100,I am still not impressed,true,true,true

The first column is a "serial", but what I see are just numbers. It
looks like an integer, it smells like an integer, I can add it to other
integers and get a second column without casting it first. So why
should I have to cast it when using MULTISET ? I don't get it.

On a related note - what is REALLY stored in the serial column? Is it 1
and 50, or is it some offset value from some base value, or whatever?
Quote:
You can, you just need to cast it. SELECT serial_key, other_value FROM TABLE(MULTISET(SELECT serial_key::INT, other_value FROM booby));


Thanks for the tip. I will give this a try.

Cheers!
-sw

Reply With Quote
select * from (select * from bob) and other easy stuff
  #7
Old 09-26-2006, 11:54 AM
Adam Tauno Williams
Junior Member


Adam Tauno Williams is offline
Adam Tauno Williams's Info
Join Date: Jan 2005
Posts: 73
Default select * from (select * from bob) and other easy stuff

On Tue, 2006-09-26 at 11:55 -0700, internetuser wrote:
Quote:
Adam Tauno Williams wrote:
Quote:
I don't know, this always made perfect sense to me. A "serial" data type's serial-ness can't be preserved through a virtual table.
But while a "serial" may be something interesting before the number is generated, once a value is actually generated and in the table, isn't it in fact just a number, sitting there, ripe for the picking?


No. Being serial does place restrictions on what the application is
free to do with it in regards to updating the record. This is why the
meta-data returned to the application when you do a select doesn't just
say INT, it will be a Serial8 or some such (depending on your
environment).
Quote:
For example - if I do something like: select myid,myid+50,


Sure but then myid+50 is an expression value, myid is still a serial.
Quote:
1,51,I am not impressed,true,true,true 50,100,I am still not impressed,true,true,true The first column is a "serial", but what I see are just numbers.


Not it your looking at the metadata returned with the query - which all
smart applications do.
Quote:
It looks like an integer, it smells like an integer, I can add it to other integers and get a second column without casting it first.


Yep, which maybe shouldn't be the case. Looks like a concession to the
lazy and hapless to me.
Quote:
So why should I have to cast it when using MULTISET ? I don't get it. On a related note - what is REALLY stored in the serial column? Is it 1 and 50, or is it some offset value from some base value, or whatever?



Reply With Quote
select * from (select * from bob) and other easy stuff
  #8
Old 09-26-2006, 01:10 PM
internetuser
Junior Member


internetuser is offline
internetuser's Info
Join Date: Sep 2006
Posts: 8
Default select * from (select * from bob) and other easy stuff

Adam Tauno Williams wrote:
Quote:
Yep, which maybe shouldn't be the case. Looks like a concession to the lazy and hapless to me.


Or perhaps a logical inconsistancy due to lazy and hapless programmers
responsible for its implementation.

Reply With Quote
select * from (select * from bob) and other easy stuff
  #9
Old 09-26-2006, 02:51 PM
Fernando Nunes
Junior Member


Fernando Nunes is offline
Fernando Nunes's Info
Join Date: Nov 2004
Posts: 25
Default select * from (select * from bob) and other easy stuff

internetuser wrote:
Quote:
Adam Tauno Williams wrote:
Quote:
I don't know, this always made perfect sense to me. A "serial" data type's serial-ness can't be preserved through a virtual table.
But while a "serial" may be something interesting before the number is generated, once a value is actually generated and in the table, isn't it in fact just a number, sitting there, ripe for the picking? For example - if I do something like: select myid,myid+50, v1,v2,v3,v4 from bob I might get: 1,51,I am not impressed,true,true,true 50,100,I am still not impressed,true,true,true The first column is a "serial", but what I see are just numbers. It looks like an integer, it smells like an integer, I can add it to other integers and get a second column without casting it first. So why should I have to cast it when using MULTISET ? I don't get it. On a related note - what is REALLY stored in the serial column? Is it 1 and 50, or is it some offset value from some base value, or whatever?
Quote:
You can, you just need to cast it. SELECT serial_key, other_value FROM TABLE(MULTISET(SELECT serial_key::INT, other_value FROM booby));
Thanks for the tip. I will give this a try. Cheers! -sw

Can you give us the bob table schema and exactly what you're trying to do?
It would be better if we could see it, instead of trying stuff that
doesn't work for you...

Regards.
Reply With Quote
select * from (select * from bob) and other easy stuff
  #10
Old 09-27-2006, 04:09 AM
macgillivary
Junior Member


macgillivary is offline
macgillivary's Info
Join Date: Jun 2006
Posts: 7
Default select * from (select * from bob) and other easy stuff

as a side note, you don't have to include lwind_name twice in the
select clause.

select lwind_name winName
from land_window
where lower(lwind_name) = 'coastal plain'


internetuser wrote:
Quote:
OK, so I have to do something like this: select lwind_name, lower(lwind_name) winName from land_window where lower(lwind_name) = 'coastal plain'


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump



Powered by: vBulletin Version 3.0.7
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Style Design by vBStyles.com


Top Contact Us - IT Forums - Archive - MyLounge Top
MyLounge.com Site Map
Forum: Cars, Cell Phone, Database, Games, Home Improvement, IT, Music, School, Sports, Web Design, Web Server, Weight Loss

The MyLounge.com forum is intended for informational use only and should not be relied upon and is not a substitute for any advice. The information contained on MyLounge.com are opinions and suggestions of members and is not a representation of the opinions of MyLounge.com. MyLounge.com does not warrant or vouch for the accuracy, completeness or usefulness of any postings or the qualifications of any person responding. Please consult a expert or seek the services of an attorney in your area for more accuracy on your specific situation. Please note that our forums also serve as mirrors to Usenet newsgroups. Many posts you see on our forums are made by newsgroup users who may not be members of MyLounge.com Term of Service