Re: Newbee question "Types"

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: pgsql-general(at)postgresql(dot)org, ken(at)perfect-image(dot)com
Subject: Re: Newbee question "Types"
Date: 2002-12-06 01:47:08
Message-ID: 200212060147.gB61l8802766@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-novice

Josh Berkus wrote:
> Ken,
>
> 1. Using column type "char" vs "varchar" vs "text"
> I understand the documented differences, but Why wouldn't
> someone just use varchar(x) instead of plain char(x)? It's
> definitely more flexable. Or would using char(x) just help one
> stay in sql conformity? How about performance differences?
> Disk space differences? Would not varchar(45) vs char(45)
> consume less space if used with less than 45 characters?
>
> In postgresql, CHAR is supplied for 3 reasons:
> 1) For compatibility with other database systems that use CHAR.
> 2) For SQL99 Compliance
> 3) For compatibility with software that expects space-filled CHAR
> fields.
>
> For a Postgres-native application, there is no reason to ever use CHAR.
> It does not perform any better, and can lead to significant annoyance.

I disagree on that one. Char _forces_ a specific length, so it pads to
the specified length. For certain applications, this can be a benefit,
and often documents that the length is exactly as specified, e.g.
CHAR(2) for US state codes.

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Josh Berkus 2002-12-06 01:48:13 Re: [GENERAL] Newbee question "Types"
Previous Message Philip Warner 2002-12-06 01:31:05 Re: [GENERAL] PostgreSQL Global Development Group

Browse pgsql-novice by date

  From Date Subject
Next Message Josh Berkus 2002-12-06 01:48:13 Re: [GENERAL] Newbee question "Types"
Previous Message Mark Wilson 2002-12-06 00:20:29 Re: Infinite Loop