Re: Efficiency question: VARCHAR with empty string vs NULL
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Doug Fields <dfields-pg-general@pexicom.com>
Cc: pgsql-general@postgresql.org
Date: 2002-05-24T18:54:14Z
Lists: pgsql-general, pgsql-sql
Doug Fields <dfields-pg-general@pexicom.com> writes: > Is there a performance difference with VARCHAR elements of value NULL and > zero-length string? These are not semantically equivalent (if you think they are, you've been using Oracle too long). You will almost certainly regret it if you try recoding your app to make them equivalent. An example: regression=# select 'foo'::varchar || ''::varchar; ?column? ---------- foo (1 row) regression=# select 'foo'::varchar || null::varchar; ?column? ---------- (1 row) But to answer your question, NULLs might save a couple bytes if there are multiple NULLs per row. I think that replacing a single empty varchar with a NULL would net out to no change (you lose the 4-byte varchar length word, but have to store a null-values bitmap instead), depending on alignment issues and how many columns there are in the table. regards, tom lane