My table is like  this

 Column  |       Type        |                          Modifiers
----------+-------------------**+-----------------------------**
------------------------------**--
 id_fld   | integer           | not null default nextval('test_table_id_fld_
**seq'::regclass)


im using Yii Framework,  How i can Put  VALUES (DEFAULT) if i put "DEFAULT"
is like a string


2013/10/31 Adrian Klaver <adrian.kla...@gmail.com>

> 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.kla...@gmail.com
>

Reply via email to