Received: from localhost (unknown [200.46.204.184]) by developer.postgresql.org (Postfix) with ESMTP id 905872E003D for ; Fri, 11 Apr 2008 18:24:45 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 59837-05 for ; Fri, 11 Apr 2008 18:24:37 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from is.rice.edu (is.rice.edu [128.42.42.24]) by developer.postgresql.org (Postfix) with ESMTP id C61822E0032 for ; Fri, 11 Apr 2008 18:24:42 -0300 (ADT) Received: from scan1.mail.rice.edu (scan1.mail.rice.edu [128.42.58.160]) by is.rice.edu (Postfix) with ESMTP id 10C214182E; Fri, 11 Apr 2008 16:24:41 -0500 (CDT) Received: from is.rice.edu ([128.42.42.24]) by scan1.mail.rice.edu (scan1.mail.rice.edu [128.42.58.160]) (amavisd-new, port 10024) with ESMTP id 19642-01; Fri, 11 Apr 2008 16:24:40 -0500 (CDT) Received: by is.rice.edu (Postfix, from userid 18612) id 590E14181D; Fri, 11 Apr 2008 16:24:40 -0500 (CDT) Date: Fri, 11 Apr 2008 16:24:40 -0500 From: Kenneth Marshall To: Chris Hoover Cc: "pgsql-admin@postgresql.org Admin" Subject: Re: What is the difference in storage between a blank string and null? Message-ID: <20080411212439.GD769@it.is.rice.edu> References: <1d219a6f0804111302r4adaf97dn4ecb0549c5ae85dc@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1d219a6f0804111302r4adaf97dn4ecb0549c5ae85dc@mail.gmail.com> User-Agent: Mutt/1.5.16 (2007-06-09) X-Virus-Scanned: by amavis-2.2.1 at scan1.mail.rice.edu X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200804/100 X-Sequence-Number: 28864 On Fri, Apr 11, 2008 at 04:02:36PM -0400, Chris Hoover wrote: > I'm doing some testing on how to decrease our database size as I work on a > partitioning scheme. > > I have found that if I have the database store all empty strings as nulls, I > get a significant savings over saving them as blank strings (i.e. ''). > Below is an example of savings I am seeing for the same table: > > In my test case, storing empty strings give me a table size of 20,635,648 > Storing empty strings as nulls gives me a table size of: 5,742,592. > > As you can see, storing empty strings as nulls is saving me approximately > 72% on this table. So, I am wanting to understand what Postgres is doing > differently with the nulls. Would someone kindly enlighten me on this. > > (P.S. I am using a nullif(trim(column),'') in my partition and view rules to > store the nulls, and coalesce(column,'') to give my application the data > back without nulls.) > > Thanks, > > Chris > > PG 8.1 > PostgreSQL stores NULLs differently. This accounts for your space difference. If you application can work with NULLs instead of '' (not the same thing), go for it. Cheers, Ken