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
1
vote
1 answer

Is it OK to add @Id to an entity which mapped to a table without Primary key column in Spring boot Jpa?

I've started working on a legacy oracle database and using Spring boot Jpa trying to insert a new row in a table (CHANNELMGR_REQUEST) without Identity: This table has a Numeric column (CM_ISN) and logically could be an Identity candidate, but I…
Mostafa
  • 3,002
  • 10
  • 52
  • 79
1
vote
2 answers

How to reset the auto generated primary key in PostgreSQL

My class for the table topics is as below. The primary key is autogenerated serial key. While testing, I deleted rows from the table and was trying to re-insert them again. The UUID is not getting reset. class Topics(db.Model): """ User Model…
1
vote
1 answer

Can't figure out what datatype is incorrect in my SQL table

I am trying to create a SQL table, but I keep getting this error. Error report - ORA-00902: invalid datatype 00902. 00000 - "invalid datatype" Here is my code. CREATE TABLE viewers ( user_id SEQUENCE PRIMARY KEY, first_name …
1
vote
3 answers

How to increment id without auto increment?

I have a table with id column as a number which have meanings. Different types of accounts start from different ranges. E.g Organisation 10000 <-> 100000, users 1000000 <-> 1kk. How can i properly increment ids on insert (with possible concurrency…
1
vote
1 answer

PostgreSQL Squence Not Working When Updating Column Details

I have created a function to update a column in a postgresSQL table using Sequence nextval() function.Function body is as follows BEGIN EXECUTE 'CREATE SEQUENCE '|| sequence_name || ' START 1'; EXECUTE 'UPDATE ' ||selected_table_name|| ' SET…
Susampath
  • 706
  • 10
  • 13
1
vote
0 answers

Serial id next value not getting sequential after failed insert attempt

I have a id field where id is serial and in the same table i have unique constraints. The problem here is when an unique constraint fails if the current ID value is 5 then after failing the next ID value gets to 7. Actually my need is to get 6 for…
Jithin Kumar S
  • 701
  • 2
  • 9
  • 20
1
vote
2 answers

Oracle - does a column have a sequence attached to it?

Kind of a general question here but is there an easy way to determine, in Oracle database, if a field has a sequence number attached to it? This seems like it should be obvious, but I'm missing it. Thanks.
alexherm
  • 1,362
  • 2
  • 18
  • 31
1
vote
3 answers

Generating incremental numbers based on a different column

I have got a composite primary key in a table in PostgreSQL (I am using pgAdmin4) Let's call the the two primary keys productno and version. version represents the version of productno. So if I create a new dataset, then it needs to be checked if…
user11962606
1
vote
2 answers

postgreSQL: primary key doesn't start on 1

I made a primary key called t_id in the table of DB by using the query t_id SERIAL PRIMARY KEY. At the very first time, it started well on 1. Then I deleted all the data and from then, it starts on 2 even though I set it on 1. Here's the screenshot…
user11492726
1
vote
1 answer

Select SEQUENCE in SQL: FROM keyword not found where expected

I created a a sequence in SQL: CREATE SEQUENCE MYSEQ increment by 5 start with 10; When I try to select the sequence: select sequence MYSEQ.nextval from DUAL; I get the error: ORA-00923: FROM keyword not found where expected 00923. 00000 - "FROM…
Joao Pedro
  • 59
  • 1
  • 9
1
vote
1 answer

Postgres - BDR replication - problem with auto_increment primary key

I have a cluster of Postgres BDR that has 2 nodes (multi master replication). I've created a table with auto increment primary key as follow: create table t1 (id serial primary key, name text); I've added some values on that table from…
user7416080
1
vote
1 answer

About the implementation details of PostgreSQL sequence

I am interested in the implementation details of sequences in PostgreSQL, the reason being that they're used in the background for the SERIAL type. I have reviewed the source file here (found in Google search: "postgresql source code sequence"),…
asafc
  • 357
  • 3
  • 21
1
vote
0 answers

Update parent child table blocks with pk generation from sequence

CREATE TABLE t1 ( t1pk NUMBER PRIMARY KEY NOT NULL ,t1val NUMBER ); CREATE TABLE t2 ( t2pk NUMBER PRIMARY KEY NOT NULL ,t2fk NUMBER ,t2val NUMBER ,CONSTRAINT t2fk FOREIGN KEY (t2fk) REFERENCES t1 (t1pk) ON DELETE…
Toru
  • 905
  • 1
  • 9
  • 28
1
vote
1 answer

Postgres Sequence reacting different to code and pgAdmin

I am working on a project with Matlab-2017b and PosgreSQL(via ODBC drivers). In the code there are some files that needed to be renamed with the database table's corresponding id number. While doing some testing with the scenario where the…
Semih SÜZEN
  • 163
  • 1
  • 2
  • 14
1
vote
2 answers

How to find the the primary key sequence and the max of primary key

I know this question is kind of silly, I need to run these queries to see if the values are out of sync, but I get an error like 'relation does not exist': SELECT MAX(the_primary_key) FROM the_table; SELECT…
ccy
  • 341
  • 6
  • 18