Postgres sequence problem.

Source: Internet
Author: User

A new table is created as follows:

1 create table hl_14.cells 2 (3 CID integer not null default nextval ('cells _ cid_seq ': regclass), 4 datetime timestamp without time zone not null, 5 cellname character varying (50) not null, -- cell name 6 nettype character varying (50) not null, -- network type GSM900, GSM1800, TD 8 CGI integer not null, -- generate the getcgi 9 RNC character varying (50) not null, 10 LAC integer not null, 11 CI integer not null, 12 Lon numeric (8, 5) not null, 13 lat numeric (8, 5) not null, 24 constraint cells_pkey primary key (CID), 25 constraint cells_key unique (datetime, CGI) 26) 27 with (28 oids = false29 ); 30 alter table hl_14.cells

Because data cannot be imported directly from the front-end file and needs to be processed, the CID is provided each time and then imported. There is no problem with this query, but an error occurs during page insertion.

Insert into cells (

Datetime, cellname,...) values (,,,). The insert statement is not for CID. As a result, an error is reported during insertion, indicating that the CID already exists. The current information of the CID sequence is as follows:
CREATE SEQUENCE cells_cid_seq  INCREMENT 1  MINVALUE 1  MAXVALUE 9223372036854775807  START 21715  CACHE 1;ALTER TABLE cells_cid_seq  OWNER TO mrapp;

That is, the start value of the sequence is not synchronously updated for the manually imported data (for CID) in the background.

There is a problem with the design of the table. It is meaningless to use CID as the primary key. So we changed the table design:

1 Create Table cells 2 (3 CID serial not null, 4 datetime timestamp without time zone not null, 5 cellname character varying (50) not null, -- cell name 6 nettype character varying (50) not null, -- network type GSM900, GSM1800, TD 8 CGI integer not null, -- generate function getcgi 9 RNC character varying (50) not null, 10 LAC integer not null, 11 CI integer not null, 12 Lon numeric (8, 5) not null, 13 lat numeric (8, 5) not null, 25 constraint cells_key unique (datetime, CGI) 26) 27 with (28 oids = false29); 30 alter table Cells

This problem is solved. The Cid is not required for import and is allocated by the database.

Postgres sequence problem.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.