Re: column type varchar(128) not null default '' vs varchar(128)

From: "Dann Corbit" <DCorbit(at)connx(dot)com>
To: <emilu(at)encs(dot)concordia(dot)ca>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: column type varchar(128) not null default '' vs varchar(128)
Date: 2006-03-08 22:59:44
Message-ID: D425483C2C5C9F49B5B7A41F8944154757D5EA@postal.corporate.connx.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> -----Original Message-----
> From: pgsql-general-owner(at)postgresql(dot)org [mailto:pgsql-general-
> owner(at)postgresql(dot)org] On Behalf Of Emi Lu
> Sent: Wednesday, March 08, 2006 2:52 PM
> To: pgsql-general(at)postgresql(dot)org
> Subject: [GENERAL] column type varchar(128) not null default '' vs
> varchar(128)
>
> Hello,
>
> When setuping column types, is there the big efficiency difference
> between the following two examples?
>
> col varchar(128) NOT NULL default ''
> vs.
> col varchar(128)

The difference has nothing to do with efficiency and everything to do
with what goes into them.

The first example does not allow col to be NULL. If you insert a row
and do not insert any data into column col, col will get a value of ''
(empty) which is not the same thing as NULL.

The second example does not have a default and allows NULL values. So
if you insert data into the table in the second example, and you do not
provide data for column col, then col will be NULL.

Browse pgsql-general by date

  From Date Subject
Next Message Steve Atkins 2006-03-08 23:03:46 Re: Fixing up a corrupted toast table
Previous Message Emi Lu 2006-03-08 22:52:02 column type varchar(128) not null default '' vs varchar(128)