Default spaces
Teradata Teradata Discussion Forums Teradata.com Discussion Forum
Visit Teradata.com
Home       Guidelines    Member List
Welcome Guest ( Login | Register )
        


This online forum is for user-to-user discussions of Teradata products, and is not an official customer support channel for Teradata. If you require direct assistance, please contact Teradata support.


Default spaces Expand / Collapse
Author
Message
Posted 3/16/2006 12:26:17 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 3/22/2006 1:31:00 PM
Posts: 2, Visits: 1
I am new to tera data. I have a doubt, that..

If a field size is 25 and the value in that is only of lenght 10 the remaining 15 places will be blank spaces?

Pls help me?
Post #3744
Posted 3/16/2006 1:59:46 PM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: 10/7/2008 12:54:51 PM
Posts: 116, Visits: 20
it depends on how you define the field.
if it is defined as field1 char(25) then the field lenght is 25 no matter what data you put in it.
if you define the field as varchar(25) then the field lenght is the size of the text that you put in it. It does not place blanks.



Feroz Shaik
Post #3747
Posted 3/22/2006 1:30:57 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 3/22/2006 1:31:00 PM
Posts: 2, Visits: 1
Thanks a lot.
Post #3810
Posted 3/23/2006 6:27:00 PM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: PAC and SFT Members
Last Login: Yesterday @ 6:11:07 PM
Posts: 331, Visits: 533
Not quite accurate, and a frequent misconception. Trimming trailing spaces from VARCHAR doesn't happen by magic - you need to be careful on the client side and/or use the TRIM function:

CREATE TABLE showVarchar( aKey INTEGER,
vText VARCHAR(25)
);

CREATE TABLE showVarchar2( aKey INTEGER,
vText VARCHAR(25)
);

insert into showVarchar values (1, 'Short');
insert into showVarchar values (2, 'Long ');
insert into showVarchar values (3, ' ');
insert into showVarchar values (4, '');

insert into showVarchar2 select * from ShowVarchar;

select aKey, vText, CHARACTERS(vText) from showVarchar2 order by aKey;

aKey vText Characters(vText)
1 Short 5
2 Long 14
3 20
4 0

Post #3823
Posted 3/24/2006 10:43:40 AM
Forum Guru

Forum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum Guru

Group: Forum Members
Last Login: 11/11/2008 8:14:01 PM
Posts: 58, Visits: 10
My understanding of Varchar has been that no trailing spaces where stored
also, and that Chars function was specially suited to Varchar for this reason.
So I reran you query

results: aKey vText Characters(vText)
1 Short 5
2 Long 5
3 1
4 0

SQL assistant Ver 6.2.0

RELEASE V2R.05.01.02.23
VERSION 05.01.02.41

Any Ideas why?

Tbob
Post #3830
Posted 3/24/2006 10:56:00 AM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: 10/7/2008 12:54:51 PM
Posts: 116, Visits: 20
Tbob That is true..
I am not sure how some one else gets different results,
I ran the same queries that you gave and got the results as expected

select aKey, vText, CHARACTERS(vText) from devdata.feroz_showVarchar2 order by aKey;


aKey vText Characters(vText)
1 Short 5
2 Long 5
3 1
4 0

and then i inserted another row in the showVarchar table

insert into devdata.feroz_showVarchar values (5, 'Ferozbbbbbbbbbb');
(the b above is to represent the blanks, the actual value was 'Feroz followed by 10 spaces')

and then i inserted this row into Showvarchar2 table

insert into devdata.feroz_showVarchar2
select * from devdata.feroz_showVarchar
where akey = 5


then i ran the character query again.
select aKey, vText, CHARACTERS(vText) from devdata.feroz_showVarchar2 order by aKey;

aKey vText Characters(vText)
1 Short 5
2 Long 5
3 1
4 0
5 Feroz 15

This is exactly what i was expecting.
Fred I am not sure how you go those results, has that got something to do with version??
Even then the concept of varchar and char should not change.


by the way i was running this in sql assistant 6.2 and we are on Teredata V2R5.

Thanks




Feroz Shaik
Post #3831
Posted 3/27/2006 11:57:38 PM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: PAC and SFT Members
Last Login: Yesterday @ 6:11:07 PM
Posts: 331, Visits: 533
In my test example, I included ten spaces after the word Long for this statement:

insert into showVarchar values (2, 'Long ');

Somehow it appears to have been truncated to a single blank in the post. But notice your tests still show 5 characters not 4 for this string - proving my point that the trailing space(s) are stored, though a bit less obvious than I intended.
Post #3861
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 7 ( 7 guests, 0 members, 0 anonymous members )
No members currently viewing this topic.


All times are GMT -5:00, Time now is 12:53am

Powered By InstantForum.NET v4.1.4 © 2008
Execution: 0.031. 7 queries. Compression Disabled.