Re: Dataypes: performance differences?

From: Andrew Sullivan <andrew(at)libertyrms(dot)info>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Dataypes: performance differences?
Date: 2002-07-31 14:16:52
Message-ID: 20020731101652.A28840@mail.libertyrms.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Jul 31, 2002 at 06:30:23PM +0900, Jean-Christian Imbeault wrote:

> However I could not find any mention of the differences in performance
> amongst the various dataypes available. I am especially interested in
> the differences between the char/varchar/text datatypes and int2/int4.

char() is only a good idea if you know that the data will always and
only be NULL or a fixed length. That is, if you have US state codes
(which are all 2 letters), char() might be a good choice. Fir such
purposes, it is reputed to be marginally faster. Otherwise, avoid
it; you'll regret it later.

As far as I know, varchar() is just window-dressing on text. So if
you don't need to restrict length, use text. If you _do_ need to
restrict length, you have to use varchar(nn).

Note that in Postgres 7.1.x and earlier, over-long varchar(nn) fields
were silently truncated; in 7.2 and later the behaviour has been made
more spec-compliant, so that you will get an error on insert. This
is another reason to use text.

There are some issues with automatic conversion of ints. For that
reason, unless you are planning to pay a lot of attention to the
matter, you are probably better off using int4 for everything. The
docs suggest that using smallint is only really a good idea where
disk space is at a premium. See

<http://www.ca.postgresql.org/users-lounge/docs/7.2/postgres/datatype.html#DATATYPE-INT>

(sorry 'bout the long line).

A

--
----
Andrew Sullivan 87 Mowat Avenue
Liberty RMS Toronto, Ontario Canada
<andrew(at)libertyrms(dot)info> M6K 3E3
+1 416 646 3304 x110

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Marc G. Fournier 2002-07-31 14:21:22 Re: Have been accepted as a writer for "The Register"
Previous Message Darren Ferguson 2002-07-31 14:10:29 Re: Have been accepted as a writer for "The Register"