Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2002
    Posts
    8

    Unanswered: Serial column problem

    Why after expicitly inserting values into a serial collumn
    my sequence for SERIAL column not updated ?
    Here is my code:

    CREATE TABLE tmp (id SERIAL, name varchar(100) NOT NULL);
    insert into tmp values (1, '11111111111');
    insert into tmp (name) values ('22222222');
    select * from tmp;
    drop table tmp;
    drop sequence tmp_id_seq;



    After executing this query:
    insert into tmp (name) values ('22222222');

    I get error:
    'Cannot insert a duplicate key into unique index tmp_id_key'

  2. #2
    Join Date
    Jul 2002
    Posts
    1
    because it should be nextval('tmp_id_seq')

  3. #3
    Join Date
    Sep 2001
    Location
    Vienna
    Posts
    400

    serial

    Let's examine these 2 rows

    insert into tmp values (1, '11111111111');

    Irt insert into field id the value 1
    THE SEQUENCE IS NOT AFFECTED

    insert into tmp (name) values ('22222222');

    if you try this query
    the sequence will be affected and try to
    insert the following:

    insert into tmp(id,name) values(1,'22222222');

    if you have a serial do not explizit give a key or if you do so you must set teh sequence to this nuber otherwise this error will occur
    http://www.postgresql.org
    --Postgresql is the only kind of thing--

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •