Questions tagged [database-sequence]

A database sequence is a number generator that produces unique numbers in a scalable and concurrency safe way.

A database sequence is a number generator that produces unique numbers in a scalable and concurrency safe way.

Once a sequence value has been generated, this number is never re-used (unless a sequence is defined to have a maximum value and cycle through its possible range).

Sequence values are not guaranteed to be gapless but offer a scalable and fast way to generate unique numbers even in high concurrency situations.

Sequences are supported by nearly all modern DBMS. However, the syntax to create them and to obtain a number from them differs between the DBMS products.

106 questions
0
votes
0 answers

Concurrency issues with Sequence in MS SQL Server?

I have a sequence in my SQL Server database CREATE SEQUENCE [dbo].[UserPKSequence] AS [int] START WITH 1 INCREMENT BY 1 MINVALUE -2147483648 MAXVALUE 2147483647 NO CACHE GO I am using this sequence on a table (lets name the table Users) that has…
0
votes
0 answers

Oracle sequence returns different value when issued from java hibernate vs sql developer

I am running into this really weird issue where an oracle sequence returns very different values when issued from java/Hibernate vs SqlDeveloper tool. @SequenceGenerator(name = "PARAM_ID_SEQUENCE", initialValue = 10, allocationSize = 30,…
Abe
  • 8,623
  • 10
  • 50
  • 74
0
votes
2 answers

Grails : id generator using assigned and falling back to sequence if unassigned

I am working with Grails 3.2.8. I would like to allow both options when generating an id. Is there a way to use assigned and falling back to sequence if unassigned? I tried getting the next id within a constructor and setting id there but running…
Mike Croteau
  • 1,062
  • 2
  • 16
  • 43
0
votes
2 answers

How to create script with Postgresql to parameterize the start value of a sequence

I'm newbie in Postgres. I use Pgadmin III and I need to parameterize a value in a statament of 'alter sequence'. I have tried to execute this code: select coalesce(MAX(ID)+1,1) as max into myTempTable from myTable; EXECUTE immediate 'ALTER SEQUENCE…
django
  • 153
  • 1
  • 5
  • 19
0
votes
1 answer

Django with legacy database - how to work with DB sequences?

Given a database table that was created using this SQL query: CREATE TABLE Bill ( Time DATE NOT NULL , Address VARCHAR2 (60) NOT NULL , ID NUMBER NOT NULL ) ; ALTER TABLE Bill ADD CONSTRAINT Bill_PK PRIMARY KEY ( ID )…
0
votes
2 answers

Reset postgres sequence to take un-used primary key ids

I am using postgres 9.5. As part of application initialization I make some inserts in database at application startup with random ids. Something like insert into student values(1,'abc') , insert into student values(10,'xyz'). Then I have some rest…
codec
  • 7,978
  • 26
  • 71
  • 127
0
votes
1 answer

Postgres 9.5: Auto increment after migrating from mysql

I am porting a MySQL database to PostgreSQL. So far I have managed to rebuild all the tables and columns and import the data. However, the auto incremented, unique id fields have not been converted properly. I used the pgAdmin GUI to correct one…
user4918296
0
votes
1 answer

How to create a database sequence which is different for different channels?

We have one requirement where different database sequences needs to be maintained for different channels. EX: ABC-SQN1, XYZ-1, and the Sequence nos needs to be incremented based on channels. Is there a way we can achieve it. Thanks
Sushma
  • 121
  • 4
  • 18
0
votes
1 answer

Why isn't NEXT VALUE allowed in CREATE FUNCTION statements?

I've been trying to create a function that uses a sequencer to return a new character ID. However it seems that DB2 doesn't allow it in CREATE FUNCTION statements. I am struggling to understand why they would do that, the only documentation they…
Adrian Bannister
  • 523
  • 4
  • 11
0
votes
2 answers

Oracle : "parsing failed" error when creating an auto_increment trigger

I'm trying to make an auto_increment trigger for the IDs of an Oracle database. After some research, I found a way to write one using a sequence and a before insert trigger. Problem is, when I execute the trigger, I have the following error…
0
votes
1 answer

How to resolve com.ibm.websphere.ce.cm.DuplicateKeyException on an identity column

caused by: com.ibm.websphere.ce.cm.DuplicateKeyException: One or more values in the INSERT statement, UPDATE statement, or foreign key update caused by a DELETE statement are not valid because the primary key, unique constraint or unique index…
panaroma
  • 1
  • 1
  • 3
0
votes
2 answers

Create sequence with specific set of values in oracle

I would like to create a sequence in oracle that will consists of two values(1, -1). Sequence will be 1,-1,1,-1,1,-1 Is it possible to create this type of sequence in oracle that will alternate between this two values only? Is this possible using…
Indiecoder
  • 186
  • 3
  • 17
-1
votes
1 answer

Analyzing production Postgres UPDATE - RETURNING query slowness

We're running a web application which has on average 10k active users, being served by 6 webnodes and backed by a Postgres 9.4.6. Our monitoring tool identified the below slow running query which often has inacceptable response times, causing…
-1
votes
1 answer

I want to create serial numbers in oracle

I want to create a serial number in Oracle. I have tried this query alter table tablename add(ID NUMBER); CREATE SEQUENCE SEQ_ID START WITH 1 INCREMENT BY 1 MAXVALUE 31611805 MINVALUE 1 NOCYCLE; UPDATE tablename SET ID= SEQ_ID.NEXTVAL I…
Akshay Patil
  • 3
  • 1
  • 5
-3
votes
1 answer

How to make sequence jump from 100 to 150

How to fire sequence to jump from 100 to 150 and followed by 152,153 and so on . .