Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: Char vs SmallInt


  • From: Gregory Stark <stark(at)enterprisedb(dot)com>
  • To: "Pg Coder" <pgcoder(at)gmail(dot)com>
  • Cc: <pgsql-general(at)postgresql(dot)org>
  • Subject: Re: Char vs SmallInt
  • Date: Sat, 21 Jul 2007 09:37:51 +0100
  • Message-id: <87ps2m6tk0(dot)fsf(at)oxford(dot)xeocode(dot)com>

"Pg Coder" <pgcoder(at)gmail(dot)com> writes:

> Which data type is smaller and will lead to better query performance -
> smallint or char?

smallint is 2 bytes, usually with 2-byte alignment.

If you declare a column as char it means CHAR(1) which in 8.2 is 5-8 bytes (5
bytes if it's an ascii character) and has 4-byte alignment. In 8.3 it's 2-5
bytes (2 bytes if it's an ascii character) and has 1-byte alignment.

If you declare a column as "char" with the quotes then it's a 1-byte integer
with 1-byte alignment. That'll be smaller than smallint.

-- 
  Gregory Stark
  EnterpriseDB          http://www.enterprisedb.com




Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group