char(1) vs varchar(1)

Moderator: NorbertKrupa

Post Reply
sreediff
Newbie
Newbie
Posts: 18
Joined: Mon Mar 28, 2016 2:51 pm

char(1) vs varchar(1)

Post by sreediff » Wed Oct 19, 2016 8:20 am

This regarding usage of data type Varchar and char for indicator columns .
I did a sample test to check the bytes used for each data type and there is no difference between bytes used for char or varchar.
Which data type occupies less space and is preferred for the usage where length is 1.

create table test_char_sri (col1 char(1));

create table test_vchar_sri (col1 varchar(1));

SELECT anchor_table_name,sum(used_bytes)
FROM
v_monitor.projection_storage
where anchor_table_name in ('test_vchar_sri','test_char_sri')
group by anchor_table_name

test_char_sri 312
test_vchar_sri 312

select * from ua3_pium.test_char_sri;
(null)

a
b
c
d
f
g
h

select * from ua3_pium.test_vchar_sri;

(null)

a
b
c
d
f
g
h

User avatar
JimKnicely
Site Admin
Site Admin
Posts: 1825
Joined: Sat Jan 21, 2012 4:58 am
Contact:

Re: char(1) vs varchar(1)

Post by JimKnicely » Wed Oct 19, 2016 2:41 pm

I don't not think there is a preference. Either is fine.
Jim Knicely

Image

Note: I work for Vertica. My views, opinions, and thoughts expressed here do not represent those of my employer.

Post Reply

Return to “Vertica Database Development”