Re: Table with Field Serial - Problem
От | Adrian Klaver |
---|---|
Тема | Re: Table with Field Serial - Problem |
Дата | |
Msg-id | 52726D58.9000908@gmail.com обсуждение исходный текст |
Ответ на | Table with Field Serial - Problem (Yostin Vargas <yostinv@gmail.com>) |
Ответы |
Re: Table with Field Serial - Problem
|
Список | pgsql-general |
On 10/31/2013 07:31 AM, Yostin Vargas wrote: > > I have a table with only one Field ID type Serial Autonumeric and is a > PK, i want insert a new record but it show me error Not null violation, > but if i put a value the first INSERT work correctly but the next > Insert it Show me error Unique violation, > > So i try adding a new field in this table and put a value null to this > field, and the ID Autonumeric work . > > Exist a way to do it only with a field, i'm working with PHP??? Some actual examples form you end would help:) My guess is you are trying to insert a NULL value into the PK field instead of just not inserting anything at all. An alternative is to use the DEFAULT keyword. See below for example. create table test_table(id_fld serial primary key, char_fld varchar); test=> \d test_table Table "public.test_table" Column | Type | Modifiers ----------+-------------------+------------------------------------------------------------- id_fld | integer | not null default nextval('test_table_id_fld_seq'::regclass) char_fld | character varying | Indexes: "test_table_pkey" PRIMARY KEY, btree (id_fld) test=> INSERT INTO test_table (id_fld , char_fld) VALUES (NULL, 't'); ERROR: null value in column "id_fld" violates not-null constraint test=> INSERT INTO test_table (char_fld) VALUES ('t'); INSERT 0 1 test=> INSERT INTO test_table (id_fld , char_fld) VALUES (DEFAULT, 't'); INSERT 0 1 > > > -- Adrian Klaver adrian.klaver@gmail.com
В списке pgsql-general по дате отправления: