can we store varchar in char

General
Highlighted

can we store varchar in char

hi iam new to teradata i wrote a procedure in tera data where it places a dummy record in parent table by checking the child table so there are 96 table for some tables he has taken varchar as primary key and for 6 tables(i know excution order of all table ) he has taken char as primary key now i have doubt whether we can store varchar declared attributes in char declared attributes can any one give me any idea how we can go furthur 

3 REPLIES
Senior Apprentice

Re: can we store varchar in char

Hi,

 

Yes you can load variable length character data values and store them in a fixed length character column. Teradata will simply right pad 'short' values with spaces to fill the declared size.

 

So, assume that you have a column defined as CHAR(20).

 

You can run either of the following statements:

insert into t1 values('david',...);

insert into t1 values('wellman',...);

For the data values shown above they will be stored as:

'david         ' <<< 15 spaces
'wellman     ' <<< 13 spaces

The same thing happens whether you load data from outside of Teradata or from an existing table (using INSERT/SELECT).

 

Once those values have been stored in the CHAR (fixed length) column they are now fixed length data values.

 

BUT, Teradata has no problem comparing fixed length to variable length columns for future processing, so this shouldn't be an issue.

 

Does this help answer your question?

 

Cheers,

Dave

 

 

Ward Analytics Ltd - information in motion
www: http://www.ward-analytics.com

Re: can we store varchar in char

Column name list is invalid. was the error iam getting when iam calling a procedure for char declared  tables 

and for varchar declared  tables there is no issue 

Senior Apprentice

Re: can we store varchar in char

Hi,

That just sounds like a naming error. Can you share examples of the code for both CHAR and VARCHAR columns along with the error message?

Cheers,

Dave

Ward Analytics Ltd - information in motion
www: http://www.ward-analytics.com