Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 30C7064FC9D for ; Fri, 12 Dec 2008 01:47:58 -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 64200-08 for ; Fri, 12 Dec 2008 01:47:54 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from ns1.aaaonlinux.net (NS1.AAAONLINUX.net [70.84.189.18]) by mail.postgresql.org (Postfix) with ESMTP id CF1DB64FC52 for ; Fri, 12 Dec 2008 01:47:53 -0400 (AST) Received: (qmail 29884 invoked by uid 508); 12 Dec 2008 05:54:24 -0000 Received: from unknown (HELO direction.biz) (59.163.21.147) by ns1.aaaonlinux.net with SMTP; 12 Dec 2008 05:54:23 -0000 Received: from [172.16.2.20] ([172.16.2.20]) (authenticated user s.borse@direction.biz) by direction.biz (direction.biz) (MDaemon PRO v9.0.0) with ESMTP id md50000215918.msg for ; Fri, 12 Dec 2008 11:15:19 +0530 Subject: Re: primary key and insert From: Suresh Borse Reply-To: s.borse@direction.biz To: Marc Fromm Cc: "pgsql-admin@postgresql.org" In-Reply-To: References: Content-Type: multipart/alternative; boundary="=-1JPN4TO+1iUhaLeHjZeC" Organization: DSS Date: Fri, 12 Dec 2008 11:08:41 +0530 Message-Id: <1229060321.2256.1.camel@dss-052.dsslp.com> Mime-Version: 1.0 X-Mailer: Evolution 2.10.3 (2.10.3-9.fc7) X-Authenticated-Sender: s.borse@direction.biz X-Spam-Processed: direction.biz, Fri, 12 Dec 2008 11:15:19 +0530 (not processed: spam filter heuristic analysis disabled) X-MDRemoteIP: 172.16.2.20 X-Return-Path: s.borse@direction.biz X-MDaemon-Deliver-To: pgsql-admin@postgresql.org X-MDAV-Processed: direction.biz, Fri, 12 Dec 2008 11:15:20 +0530 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 200812/103 X-Sequence-Number: 30936 --=-1JPN4TO+1iUhaLeHjZeC Content-Type: text/plain Content-Transfer-Encoding: 7bit Create a sequence and use the sequence in your insert statement. On Thu, 2008-12-11 at 15:27 -0800, Marc Fromm wrote: > I created this table: > Column | Type | Modifiers > ------------+------------------------+------------------------ > first_name | character varying(20) | > last_name | character varying(30) | > w_number | character varying(9) | > alert | character varying(200) | > post_date | date | > 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 > > $sql = "INSERT INTO alert_list ( > w_number, > first_name, > last_name, > alert, > post_date > ) > VALUES ( > '$txtStudentNumber', > '$txtStudentFirstName', > '$txtStudentLastName', > '$txtStudentAlert', > 'now()' > )"; > > How do I do an insert on this table and have the primary key "id" > update with the record? > > thanks > > Marc Thanks & Regards, Suresh Borse (DBA) _________________________________________________________________________________________ DIRECTION SOFTWARE SOLUTIONS 5, Brady Gladys Plaza, 1/447, Senapati Bapat Marg, Lower Parel, Mumbai - 400 013 Tel. : 91 22 66615000 (Ext: 350) Fax : 91 22 24911046 Cell : 91 9422 239338 Site : www.direction.biz _________________________________________________________________________________________ --=-1JPN4TO+1iUhaLeHjZeC Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 7bit Create a sequence and use the sequence in your insert statement.


On Thu, 2008-12-11 at 15:27 -0800, Marc Fromm wrote:
I created this table:
   Column   |          Type                   | Modifiers
    ------------+------------------------+------------------------
   first_name | character varying(20)  |
  last_name  | character varying(30)  |
 w_number   | character varying(9)    | 
      alert      | character varying(200) | 
  post_date  | date                           |
       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
 
$sql = "INSERT INTO alert_list (
                      w_number,
                      first_name,
                      last_name,
                      alert,
                      post_date
                  )
                  VALUES (
                      '$txtStudentNumber',
                      '$txtStudentFirstName',
                      '$txtStudentLastName',
                      '$txtStudentAlert',
                      'now()'
                  )";

How do I do an insert on this table and have the primary key "id" update with the record?
 
thanks
 
Marc
Thanks & Regards,

Suresh Borse
(DBA)
_________________________________________________________________________________________
DIRECTION SOFTWARE SOLUTIONS
5, Brady Gladys Plaza, 1/447, Senapati Bapat Marg, Lower Parel, Mumbai - 400 013
Tel.   : 91 22 66615000     (Ext: 350)             Fax    : 91 22 24911046             
Cell   : 91 9422 239338                               Site    : www.direction.biz
_________________________________________________________________________________________
--=-1JPN4TO+1iUhaLeHjZeC--