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

How to create a cyclic sequence in snowflake data warehouse

I am looking for Sequence with a Cycle in Snowflake data warehouse like in Oracle. I guess Snowflake data warehouse doesn't have this built-in. Any idea how to implement ?
dks551
  • 1,113
  • 1
  • 15
  • 39
1
vote
1 answer

When should I use CYCLE in a sequence?

I'm using sequences in a PostgreSQL database to insert rows into tables. When creating the sequences I have never used the CYCLE option on them. I mean they can generate pretty big numbers (in the order of 2^63 as far as I remeber) and I don't…
The Impaler
  • 45,731
  • 9
  • 39
  • 76
1
vote
0 answers

Generate unique ID append sequence

I have a challenge in SQL Server that I would really appreciate your help on. We have a unique value that we store in a string field for records that makes it easier for a user to recognize it e.g. ABC001 or XX01 or anything else that the user wants…
user2470338
1
vote
1 answer

postgresql nextval incorrect result

After restoring database I run next query SELECT nextval('table_id_seq') and I must get max id + 1 something like (select max(id) + 1 from table), but instead I get just max id next time I call it result is correct. This issue happens only to two…
Roman
  • 11
  • 4
1
vote
4 answers

sequence number not allowed here in same session

How can i get current rule id in a same session because select ID from rules where ID=rules_seq.currval is throwing error : ORA-02287: sequence number not allowed here
shrawan
  • 37
  • 3
1
vote
0 answers

How I can create sequence like thing in MySql

I know that, there is no support for sequences in MySql. We can use Auto increment column for that. But in my scenario, in our application we gives user privilege to create sequence in database which is used for sequencing the file list on disk. For…
Chintan Patel
  • 729
  • 3
  • 14
  • 31
1
vote
1 answer

Maximum value allowed for CACHE in CYCLE sequence

CREATE SEQUENCE demo_seq START WITH 1 INCREMENT BY 3 MINVALUE 1 MAXVALUE 14 CYCLE CACHE (?); According to formula i.e. (CEIL(MAXVALUE-MINVALUE))/ABS(INCREMENT) So, (CEIL(14-1))/ABS(3) The value is 4.33 So what is the CACHE value for the above…
user5499810
  • 41
  • 1
  • 9
1
vote
1 answer

Oracle change increment_by on a sequence

ALTER SEQUENCE my_sequence INCREMENT BY '1000000000' - TO_NUMBER(SELECT last_number FROM all_sequences WHERE sequence_name='my_sequence'); Can someone explain to me why it throws 'Incorrect number'? I tried putting TO_NUMBER everywhere, I tried…
Shadov
  • 5,421
  • 2
  • 19
  • 38
0
votes
0 answers

Does hbase have similar feature as nextval('sequence_name') provided by postgres db

Is there any feature in hbase to create and use sequence similar to postgres like below CREATE SEQUENCE: CREATE SEQUENCE schemaname."SEQUENCE_123456" INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 20 NO…
0
votes
0 answers

Sequence in DB Postgresql

I have a Java system that uses Sequence in PK in database (postgreSQL and PGadmin) This sequence should take the current month (with two digits) followed by the current year. It turns out that a certain time of day arrives and the command below is…
Raquelhe
  • 3
  • 2
0
votes
1 answer

ALTER TABLE in Postgres with a subquery

I am trying to update the identity sequence in my table, but I am getting a syntax error. This works: ALTER TABLE "ApiResourceScopes" ALTER COLUMN "Id" RESTART SET START 145 This doesn't work: ALTER TABLE "ApiResourceScopes" ALTER COLUMN "Id" …
0
votes
1 answer

Hibernate Sequence Logic

I am having a constraint violation issue with Hibernate and the constraint is related primary key. I debugged a bit and see that the before insertion, sequence value selection as below select table_seq.nextval from dual; runs only at the beginning…
Olgun Kaya
  • 2,519
  • 4
  • 32
  • 46
0
votes
1 answer

Why SEQUENCE is used in SQL?

I am brushing up my knowledge about SQL and I am learning more and more. However, I am not understanding the purpose of the Sequence we use. I am using SQL Server.
cbirole
  • 27
  • 2
0
votes
1 answer

How to fix NEXTVAL returning null in insert query but returns correct value when executed alone in PostgreSQL?

When I execute the following insert query: insert into FEED_STAGING_GOOD_TRADE (JOBEXECUTIONID, STAGINGID, ROWNUMBER, system, traderef, mtmvaluation, mtmvaluationccy, prcmtmquality, prcdate) values (64, NEXTVAL('FEED_STAGING_TRADE_SEQ')…
Amine
  • 901
  • 2
  • 14
  • 33
0
votes
1 answer

PostgreSQL ALTER SEQUENCE with SELECT clause

I am trying to alter database sequence and restart it with value returned by complex SELECT statement. This is a simplified example that I prepared to replicate the issue: ALTER SEQUENCE abc.my_seq RESTART WITH (SELECT 1234) When I run this…
Sam Carlson
  • 1,891
  • 1
  • 17
  • 44