Try and see; delete the ending "," after "different" on the second and third so that they are executed, execute each of them, and then do:
\d testtable
after each, and you can see what happens. Then release the table and move on to the next. It will look like this:
Column | Type | Modifiers --------+-------------------+-------------------------------------------------------- id | integer | not null default nextval('testtable_id_seq'::regclass) title | character varying | Indexes: "id" PRIMARY KEY, btree (id) Column | Type | Modifiers --------+-------------------+-------------------------------------------------------- id | integer | not null default nextval('testtable_id_seq'::regclass) title | character varying | Indexes: "testtable_pkey" PRIMARY KEY, btree (id) Column | Type | Modifiers --------+-------------------+----------- id | integer | not null title | character varying | Indexes: "testtable_pkey" PRIMARY KEY, btree (id)
The first and second are almost identical, except that the generated primary key is named differently. In the third case, this sequence is no longer populated when inserted into the database. First you need to create a sequence, and then create a table as follows:
CREATE TABLE testtable ( id integer PRIMARY KEY DEFAULT nextval('testtable_id_seq'), title character varying );
To get what looks the same as the second. The only drawback is that you can use the CACHE directive to pre-allocate a certain number of sequence numbers. This is possible in order to be a sufficiently large resource that needs to be reduced. But you will need to do several thousand inserts per second, not per minute, before this happens.
Greg smith
source share