Connecting Tech Pros Worldwide Help | Site Map

Insert value to auto increment colomn

  #1  
Old June 3rd, 2009, 11:49 AM
Familiar Sight
 
Join Date: Jan 2008
Posts: 196
I'm a new to postgres. i have a table which is having a colomn with auto increment value. When I insert value to that table, it gives an error.

Quote:
$pgsql = "INSERT INTO xxx VALUES (null,'$FullName', '$DoB', '$Address','$PhnNo' )";

Error in SQL query: ERROR: null value in column "No" violates not-null constraint

First column is the auto increment one.
Could some one help me?
  #2  
Old June 5th, 2009, 09:43 AM
Moderator
 
Join Date: Dec 2006
Location: Europe
Posts: 290

re: Insert value to auto increment colomn


If it is autoincrement column, why do yo want to put a value here. Let postgres put this value, unless you have a good reason to put value by yourself.

To let postgres to put a value write
Expand|Select|Wrap|Line Numbers
  1. $pgsql = "INSERT INTO xxx(HERE WRITE COMMA-SEPARATED COLUMNS WICH YOU FILL WITH VALUES) VALUES ('$FullName', '$DoB', '$Address','$PhnNo' )"; 
  2.  
for example
Expand|Select|Wrap|Line Numbers
  1. $pgsql = "INSERT INTO xxx(full_name,some_column,address,phone) VALUES ('$FullName', '$DoB', '$Address','$PhnNo' )"; 
  2.  
Reply