dbTalk Databases Forums  

length(PUBLIC) = 8 why?

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


Discuss length(PUBLIC) = 8 why? in the comp.databases.ibm-db2 forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
cbielins@gmail.com
 
Posts: n/a

Default length(PUBLIC) = 8 why? - 03-08-2011 , 06:05 PM






Hey guys...


Just wondering about the reserved word PUBLIC used in DB2. The length
of that word is 8 and it screwing with some formatting work that I'm
doing. Does anyone know why? Is it because PUBLIC is a reserved word
and DB2 adds a newline to the end of them?

Any way to remove the newline? R/LTRIM doesn't work and I can't use a
SUBSTR because of other ids inside, say, the TABAUTH table.

Reply With Quote
  #2  
Old   
Helmut Tessarek
 
Posts: n/a

Default Re: length(PUBLIC) = 8 why? - 03-08-2011 , 06:36 PM






On 08.03.11 19:05 , cbielins (AT) gmail (DOT) com wrote:
Quote:
Just wondering about the reserved word PUBLIC used in DB2. The length
of that word is 8 and it screwing with some formatting work that I'm
doing. Does anyone know why? Is it because PUBLIC is a reserved word
and DB2 adds a newline to the end of them?

Any way to remove the newline? R/LTRIM doesn't work and I can't use a
SUBSTR because of other ids inside, say, the TABAUTH table.
I'm sorry, I have no clue what you are talking about. Can you be a little bit
more specific? What do you mean by length(PUBLIC) = 8?

$ db2 "values length(PUBLIC)"
SQL0206N "PUBLIC" is not valid in the context where it is used.
SQLSTATE=42703
$ db2 "values length('PUBLIC')"

1
-----------
6

1 record(s) selected.


--
Helmut K. C. Tessarek
DB2 Performance and Development
IBM Toronto Lab

Reply With Quote
  #3  
Old   
cbielins@gmail.com
 
Posts: n/a

Default Re: length(PUBLIC) = 8 why? - 03-08-2011 , 07:01 PM



On Mar 8, 4:36*pm, Helmut Tessarek <tessa... (AT) evermeet (DOT) cx> wrote:
Quote:
On 08.03.11 19:05 , cbiel... (AT) gmail (DOT) com wrote:

Just wondering about the reserved word PUBLIC used in DB2. *The length
of that word is 8 and it screwing with some formatting work that I'm
doing. *Does anyone know why? *Is it because PUBLIC is a reserved word
and DB2 adds a newline to the end of them?

Any way to remove the newline? *R/LTRIM doesn't work and I can't use a
SUBSTR because of other ids inside, say, the TABAUTH table.

I'm sorry, I have no clue what you are talking about. Can you be a littlebit
more specific? What do you mean by length(PUBLIC) = 8?

$ db2 "values length(PUBLIC)"
SQL0206N *"PUBLIC" is not valid in the context where it is used.
SQLSTATE=42703
$ db2 "values length('PUBLIC')"

1
-----------
* * * * * 6

* 1 record(s) selected.

--
Helmut K. C. Tessarek
DB2 Performance and Development
IBM Toronto Lab
That's interesting Helmut! If you do a "select grantee,
length(grantee) from syscat.tabauth" you'll find that the length of
PUBLIC is 8, not 6. I thought that it may be due to it being a
reserved word.

Plus, when I feed a query into a bash variable (knowing it is PUBLIC)
and evaluate it, the data shows that there is a newline at the end of
the word, which, again, lead me to believe that DB2 designates their
reserved words with a newline.

Here is what I used:

db2 "select grantee, length(grantee) as length from syscat.tabauth
fetch first 5 rows only"

GRANTEE LENGTH
--------------------------------- -----------
PUBLIC 8
PUBLIC 8
PUBLIC 8
PUBLIC 8
PUBLIC 8

bash> var=`db2 -x "select grantee from syscat.tabauth fetch first 1
rows only"`
bash> echo $var
PUBLIC
bash> echo $var | wc -m
7 (this was also wierd)
bash> echo $var | xxd
0000000: 5055 424c 4943 0a PUBLIC.

The last '0a' translates to a newline. So I guess, I'm wondering I
can remove that newline because it is pushing some XML formatting over
too far.

Reply With Quote
  #4  
Old   
Helmut Tessarek
 
Posts: n/a

Default Re: length(PUBLIC) = 8 why? - 03-08-2011 , 08:17 PM



Ok, now I understand what you mean.

Quote:
I thought that it may be due to it being a reserved word.
The length for grantee in syscat.tabauth and sysibm.systabauth is always 8
characters minimum. You can try to grant access on a table to a user with 4
characters. You will see that the length is also 8. A detailed explanation
would probably take too long and would not really help you either.
But I try to make it short. Internally DB2 is padding the grantee with spaces
up to 8 characters. So the value which is in the catalog table is actually:
'PUBLIC '
or for a user called xyz:
'XYZ '
Therefore the length is 8.
You can get the correct length for grantee with:

db2 "select grantee, length(rtrim(grantee)) as length from syscat.tabauth
fetch first 5 rows only"

Quote:
Plus, when I feed a query into a bash variable (knowing it is PUBLIC) and
evaluate it, the data shows that there is a newline at the end of the word,
which, again, lead me to believe that DB2 designates their reserved words
with a newline.
No, the newline is added by the echo command.

See what happens, if you do the following:

echo 'Test' |xxd

Quote:
The last '0a' translates to a newline. So I guess, I'm wondering I can
remove that newline because it is pushing some XML formatting over too
far.
echo -n "Test' |xxd

--
Helmut K. C. Tessarek
DB2 Performance and Development
IBM Toronto Lab

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

Default Re: length(PUBLIC) = 8 why? - 03-09-2011 , 04:01 AM



The reason for this is that SCHEMA as well as USER used to be a CHAR(8)
rather than the VARCHAR it is today.
So to keep backwarsd compatibility the blank padding to 8 is performed.
Why did you say RTRIM doesn't work for you?

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
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.