dbTalk Databases Forums  

Column names with spaces - How could db2 allow its creation?

comp.databases.ibm-db2 comp.databases.ibm-db2


Discuss Column names with spaces - How could db2 allow its creation? in the comp.databases.ibm-db2 forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Arun Srini
 
Posts: n/a

Default Column names with spaces - How could db2 allow its creation? - 05-20-2011 , 02:53 PM






I just want to know how db2 can allow creating columns with spaces
between them . I was able to create this in db2 udb 9.7

create table arun.test1("a b" int);

and was able to access the row when I use double quotes. Is this ok?
If there are information regarding how and why it can happen please
link them in the reply. Is this a codepage issue?

Reply With Quote
  #2  
Old   
Lennart Jonsson
 
Posts: n/a

Default Re: Column names with spaces - How could db2 allow its creation? - 05-20-2011 , 04:17 PM






On 2011-05-20 21:53, Arun Srini wrote:
Quote:
I just want to know how db2 can allow creating columns with spaces
between them . I was able to create this in db2 udb 9.7

create table arun.test1("a b" int);

and was able to access the row when I use double quotes. Is this ok?
Yes, but I would advise against it. Normally db2 stores identifiers such
as tablenames in upper case, and also transforms them to uppercase when
used in queries. But if you quote an identifier with double quotes, it
is stored as is in the catalog. Example:

create table arun.test1("ab" int);
select * from arun.test1 where ab = 3
SQL0206N "AB" is not valid in the context where it is used. SQLSTATE=42703

select * from arun.test1 where "ab" = 3
ab
-----------

0 record(s) selected.

/Lennart

Reply With Quote
  #3  
Old   
Serge Rielau
 
Posts: n/a

Default Re: Column names with spaces - How could db2 allow its creation? - 05-20-2011 , 06:12 PM



On 5/20/2011 3:53 PM, Arun Srini wrote:
Quote:
I just want to know how db2 can allow creating columns with spaces
between them . I was able to create this in db2 udb 9.7

create table arun.test1("a b" int);

and was able to access the row when I use double quotes. Is this ok?
If there are information regarding how and why it can happen please
link them in the reply. Is this a codepage issue?
Using double quotes forces DB2 to take the identifiers "as-is"
Using spaces is definitely not best practices.
If you want to pile insult ontop of injury you can escape the double quotes:
"a""b".. yummy.
Not all features that are legal are encouraged....

Cheers
Serge


--
Serge Rielau
SQL Architect DB2 for LUW, IBM Toronto Lab
Blog: tinyurl.com/SQLTips4DB2
Wiki: tinyurl.com/Oracle2DB2Wiki
Twitter: srielau

Reply With Quote
  #4  
Old   
Will Honea
 
Posts: n/a

Default Re: Column names with spaces - How could db2 allow its creation? - 05-20-2011 , 10:32 PM



Serge Rielau wrote:

Quote:
Not all features that are legal are encouraged....
That also applies to names with apostrophes. O'Grady drives me nuts!

--
Will Honea

Reply With Quote
  #5  
Old   
--CELKO--
 
Posts: n/a

Default Re: Column names with spaces - How could db2 allow its creation? - 05-21-2011 , 08:45 AM



Yes, double quotes are part of the ANSI/ISO standards. It is one of
our biggest mistrakes. Do not use it. Follow the ISO rules aoubt using
only alphas, digits and underscores; this will let your data element
names will port to all the X3J languages and other tools.

There are bad SQL programmers who use this feature to do display
formatting in the database. When someone does this, it is a symptom of
other bad code. They do not understand how a tiered architecture
works.

Reply With Quote
  #6  
Old   
Arun Srini
 
Posts: n/a

Default Re: Column names with spaces - How could db2 allow its creation? - 05-21-2011 , 12:55 PM



On May 21, 8:45*am, --CELKO-- <jcelko... (AT) earthlink (DOT) net> wrote:
Quote:
Yes, double quotes are part of the ANSI/ISO standards. It is one of
our biggest mistrakes. Do not use it. Follow the ISO rules aoubt using
only alphas, digits and underscores; this will let your data element
names will port to all the X3J languages and other tools.

There are bad SQL programmers who use this feature to do display
formatting in the database. When someone does this, it is a symptom of
other bad code. They do not understand how a tiered architecture
works.
This was the explanation I was looking forward to. Thanks Joe.

Reply With Quote
Reply




Thread Tools
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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.