primary key and insert

From: Marc Fromm <Marc(dot)Fromm(at)wwu(dot)edu>
To: "pgsql-admin(at)postgresql(dot)org" <pgsql-admin(at)postgresql(dot)org>
Subject: primary key and insert
Date: 2008-12-11 23:27:59
Message-ID: B0D7C0A3F35FE144A70312D086CBCA9B0213C0B95D@ExchMailbox2.univ.dir.wwu.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

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<http://finaid46.finaid.wwu.edu/lan/student_alerts/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

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Steve Crawford 2008-12-12 00:39:43 Re: primary key and insert
Previous Message paulo matadr 2008-12-11 18:40:13 Tool to converter plsql in pgplsql