Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id C8EA364FED7 for ; Thu, 11 Dec 2008 20:39:49 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 15901-05 for ; Thu, 11 Dec 2008 20:39:45 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from polaris.pinpointresearch.com (66-7-238-130.static-ip.telepacific.net [66.7.238.130]) by mail.postgresql.org (Postfix) with ESMTP id DCEC764FCF5 for ; Thu, 11 Dec 2008 20:39:45 -0400 (AST) Received: from [192.168.1.179] (betelgeuse.pinpointresearch.com [192.168.1.179]) by polaris.pinpointresearch.com (Postfix) with ESMTP id B1AA2E00EC85; Thu, 11 Dec 2008 16:39:43 -0800 (PST) Message-ID: <4941B2CF.1040906@pinpointresearch.com> Date: Thu, 11 Dec 2008 16:39:43 -0800 From: Steve Crawford User-Agent: Thunderbird 2.0.0.18 (X11/20081125) MIME-Version: 1.0 To: Marc Fromm CC: "pgsql-admin@postgresql.org" Subject: Re: primary key and insert References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200812/101 X-Sequence-Number: 30934 Marc Fromm wrote: > I created this table: > ... > id | integer | not null > Indexes: > "alert_list_pkey" PRIMARY KEY, btree (id) > I get this error when I run the insert a listed below. The insert does > not have an entry for the primary key "id" since I thought it updates > automatically: > *Warning*: pg_query() [function.pg-query > ]: > Query failed: ERROR: null value in column "id" violates not-null > constraint > ... > How do I do an insert on this table and have the primary key "id" > update with the record? > I think you are confusing primary key and serial. A column can be a primary key (not-null, unique row id) or a serial (actually automatically creates an integer type, a sequence, and a default for the column of nextval('sequence') to automatically generate a new value for each record). A primary key could be a serial, but doesn't have to be. A serial can be a primary key but doesn't have to be. Note: due to things like transaction rollbacks, a serial column will have unique IDs generated but they are not guaranteed to be consecutive. Cheers, Steve