Insert value to auto increment colomn

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ghjk
    Contributor
    • Jan 2008
    • 250

    Insert value to auto increment colomn

    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.

    $pgsql = "INSERT INTO xxx VALUES (null,'$FullNam e', '$DoB', '$Address','$Ph nNo' )";

    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?
  • rski
    Recognized Expert Contributor
    • Dec 2006
    • 700

    #2
    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
    Code:
    $pgsql = "INSERT INTO xxx(HERE WRITE COMMA-SEPARATED COLUMNS WICH YOU FILL WITH VALUES) VALUES ('$FullName', '$DoB', '$Address','$PhnNo' )";
    for example
    Code:
    $pgsql = "INSERT INTO xxx(full_name,some_column,address,phone) VALUES ('$FullName', '$DoB', '$Address','$PhnNo' )";

    Comment

    Working...