Re: Null records inserted

From: "Eric G(dot) Miller" <egm2(at)jps(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Null records inserted
Date: 2001-03-24 03:04:50
Message-ID: 20010323190450.A25015@calico.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, Mar 24, 2001 at 01:07:08PM +1030, Stephen Davies wrote:
> Hello.
>
> I have a PostgreSQL (V7.0.2) database with several tables defined with
> a primary key set by default to a sequence value.
>
> 99% of the time this works as expected but there is a trickle of
> records appearing in each table where every field is null.
>
> Could somebody please explain to me how this is possible so that I
> might be able to track down the programming error that causes them.
>
> That is, how can a field that is defined as having a default value wind
> up in the database as null.
>
> Despite the usual rules regarding null processing, I would still expect
> a second unique primary key value of null to be rejected.
>
> The database is usually maintained via a VB5 ODBC application.

Question, is the primary key a multicolumn key? If so, you need to have
NOT NULL constraints on each of the columns. Otherwise, I don't see how
an integer primary key could ever get a NULL value (bug?).

Try this:

create sequence foo_id_seq;

create table foo (id integer DEFAULT nextval('foo_id_seq'), name text);

insert into foo (name) values ('bar');

update foo set id = NULL, name = NULL where id = currval('foo_id_seq');

Now you should have a record with all NULL values. If however, "id" is
defined with a PRIMARY KEY constraint (or as SERIAL "datatype") the
update should fail.

--
Eric G. Miller <egm2(at)jps(dot)net>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ron Peterson 2001-03-24 03:05:52 Re: HOWTO for pg 7.1 installation from cvs
Previous Message Stephen Davies 2001-03-24 02:37:08 Null records inserted