pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Suresh Borse <s.borse@direction.biz>
To: Marc Fromm <Marc.Fromm@wwu.edu>
Cc: pgsql-admin@postgresql.org <pgsql-admin@postgresql.org>
Subject: Re: primary key and insert
Date: Fri, 12 Dec 2008 11:08:41 +0530
Message-ID: <1229060321.2256.1.camel@dss-052.dsslp.com> (raw)
In-Reply-To: <B0D7C0A3F35FE144A70312D086CBCA9B0213C0B95D@ExchMailbox2.univ.dir.wwu.edu>
References: <B0D7C0A3F35FE144A70312D086CBCA9B0213C0B95D@ExchMailbox2.univ.dir.wwu.edu>

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
_________________________________________________________________________________________

view thread (4+ messages)

Message-ID: <1229060321.2256.1.camel@dss-052.dsslp.com>
Permalink:  ../1229060321.2256.1.camel@dss-052.dsslp.com/
Also on:    postgresql.org/message-id/1229060321.2256.1.camel@dss-052.dsslp.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: s.borse@direction.biz, Marc.Fromm@wwu.edu
  Subject: Re: primary key and insert
  In-Reply-To: <1229060321.2256.1.camel@dss-052.dsslp.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox