BINARY/VARBINARY vs. CHAR/VARCHAR

Moderator: NorbertKrupa

Post Reply
harryrundles
Intermediate
Intermediate
Posts: 96
Joined: Thu Jul 19, 2012 12:33 am

BINARY/VARBINARY vs. CHAR/VARCHAR

Post by harryrundles » Fri Aug 16, 2013 2:03 pm

Hey,

Is there any reason to use the BINARY and VARBINARY data types instead of CHAR and VARCHAR? They all store up to 65,000 bytes so I don't understand the difference between them.
Thanks,
Harry

id10t
GURU
GURU
Posts: 732
Joined: Mon Apr 16, 2012 2:44 pm

Re: BINARY/VARBINARY vs. CHAR/VARCHAR

Post by id10t » Mon Aug 19, 2013 9:35 am

Hi!

How you will store binary data(images for example)? As CHAR/VARCHAR? There are some compatibility between char and binary for text/letters (strings are stored as binary data on a bottom layer), that why it's doesn't matter for strings, but matter for binary data. Binary data can be printed as text (with hexdump for example) or can be executed by OS.

Binary data (can be printed or executed):

Code: Select all

$ file /bin/cp
cp: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0x1f9374eeb4ce33dbe93ff8fb933700a898e4346a, stripped

Code: Select all

$ hexdump -C /bin/cp | head -5
00000000  7f 45 4c 46 02 01 01 00  00 00 00 00 00 00 00 00  |.ELF............|
00000010  02 00 3e 00 01 00 00 00  10 34 40 00 00 00 00 00  |..>......4@.....|
00000020  40 00 00 00 00 00 00 00  68 e5 01 00 00 00 00 00  |@.......h.......|
00000030  00 00 00 00 40 00 38 00  09 00 40 00 1c 00 1b 00  |....@.8...@.....|
00000040  06 00 00 00 05 00 00 00  40 00 00 00 00 00 00 00  |........@.......|

Post Reply

Return to “Vertica Database Development”