Questions tagged [sequence]

An object that can generate unique integers.

Filter by
Sorted by
Tagged with
0
votes
1answer
15 views

How to set current sequence while converting primary key serial(integer) to bigserial(bigint)

The table already has few thousands of rows and I want to convert the primary key from Integer to BigInteger. How to change the sequence for biginteger? --Create new temp sequence (sequence-name1) ...
0
votes
1answer
21 views

Create sequence starting with maximum id from a table [duplicate]

I'm trying to create a sequence in the following way: create sequence some_seq start with (select max(id) + 1 from some_table); But I'm getting the following error: ERROR: syntax error at or near "(...
8
votes
2answers
839 views

Does ordering by auto-incrementing PK ensure chronological order?

Is it safe to assume that ordering by an auto-incrementing PK in Postgres will order the records chronologically, from a creation standpoint? I have a many to many relationship, from which I don't ...
2
votes
1answer
60 views

Are SqlServer Sequences, guaranteed to return different values for concurrent transactions?

In documentation it is told that: Duplicate validation only occurs once a record is fully populated. This can result in some cases where the same number is used for more than one record during ...
1
vote
1answer
30 views

how to alter sequence in db2 stored procedure by another user

I am using DB2 LUW Version 10.5.0.5 on Linux (x86_64) I have written a procedure to alter a sequence to restart with a certain number. The procedure takes the sequence name and the number to restart ...
4
votes
2answers
224 views

How can I safely rename a sequence in PostgreSQL, ideally without downtime?

We want to rename some sequences in our production database for certain reasons. Is there a way to do this safely in production without having to first close all connections to the database? It's ...
-1
votes
2answers
55 views

Generating millions of sequences in Postgres (with Redis)

I am creating a chat application, and I will save chat messages for all conversations and users in one partitioned (on convo ids), BRIN indexed table. When my server wants to store new messages it has ...
1
vote
1answer
11 views

Postgres sequence get last usage

I have a database that has both sequenced correlated to table unique ids and "standalone" but having values. I need to know which ones are really used but I'm not the owner of every procedure running ...
0
votes
1answer
31 views

MariaDB, SEQUENCE engine, dynamic upper bound

I'd like to generate a sequence in MariaDB starting at 1 and ending with whatever is the largest id in some other table. That other table has roughly this schema: create table main ( id integer ...
1
vote
1answer
673 views

Postgres: Get nextval in sequence without actually incrementing sequence?

It looks like select nextval('table_name') actually does the value increment. My goal is to "predict" the nextval value on all tables in the database without actually making any incrementation. This ...
1
vote
0answers
45 views

Sequence number for COMMITTED concurrent inserts

For example, I have a table create table Queue (OrderNum int, Data varchar(1000)) --int - may be a different type and many concurrent inserts into this table. Is there is a way to fill the OrderNum ...
1
vote
1answer
103 views

Create sequence based on the value of another column

I have to create sequence numbers based on related user. Like: ╔════════════╦═════════════╦═══════════════════╗ ║ Row Id ║ User Id ║ Sequence Number ║ ╠════════════╬═════════════╬═══════════...
-2
votes
1answer
48 views

INSTEAD OF INSERT does not display changes

This is my table: CREATE TABLE [MyTable] ( [GroupId] INT NOT NULL, [ItemId] INT NOT NULL, [Data] INT NOT NULL, PRIMARY KEY CLUSTERED ([GroupId], [...
0
votes
1answer
27 views

Postgres - how to investigate a dependency before DROPing a field

I want to drop a field from a partitioned table, POSTGRES claims there are dependencies and proposes using CASCADE. How can I check that nothing important will be deleted before risking DROP with ...
0
votes
0answers
276 views

Reset all sequences so that they continue after max(id) + 1?

It looks like I messed up a database migration and while all sequences are there, they would start at 1, which triggers errors like: django.db.utils.IntegrityError: duplicate key value violates ...
1
vote
1answer
111 views

Determine Sequence last used value for sql server before 2017

I've got an issue with sql server before 2017. Its regarding current value and next value of a sequence. In 2017 you can determine based on the last_value_used that current_value is the last value or ...
0
votes
1answer
2k views

Change LAST_NUMBER value in a sequence (NEXTVAL)

My question seems easy but i haven't found a solution. I'm using the nexval sequence in a insert SQL script but we have errors because the LAST_NUMBER value haven't been updated and its value is not ...
0
votes
2answers
36 views

Sequence cache size [closed]

I have to change cache for all sequences in schema and database. I can not change one by one. Is there some script or query which can change cache size for all sequences?
1
vote
1answer
75 views

Oracle - Sync Sequence nextval using CONNECT - side effects?

DB Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Action After a data migration - from an old table to a new table - we created a new sequence and executed this command to sync ...
0
votes
1answer
359 views

How currval of sequence being preserved during the backup and restore in postgres

If I do backup and restore a huge db (tons of tables in it), will it run without any issues rather rising exception about duplicate key constraints of sequenced column(s). While taking pg_dump (...
0
votes
1answer
27 views

Sequence according to value from table in postgresql [duplicate]

I have dictionary_type and dictionary_value tables. Value is connected with type. I would like to create sequence which will set the id of values according to type id. Expected dictionary_type: id ...
3
votes
2answers
3k views

GRANT SELECT ON SEQUENCE succeeds, but to no effect?

I am trying to grant select access to sequences from one user/role to another. There are no errors when I run the command but once run, the second role is unable to view the sequences. I have run the ...
0
votes
2answers
503 views

Permissions on SQL Server Sequences

The AD Group to which I belong has db_owner permissions on database LandingZone. The application I am debugging, that is running under my ID, is doing a SELECT NEXT VALUE FOR ThisSchema.ThatSequence. ...
2
votes
1answer
37 views

step interpolation

My data: +------------+-------+ | date | value | +------------+-------+ | 2018-12-01 | 10 | | 2018-12-09 | 15 | | 2018-12-17 | 12 | +------------+-------+ My goal: +------------+-----...
0
votes
2answers
1k views

how to create custom id in sql server with sequence

How can I create a table with custom ID like BK-0001001 with a sequence. Sorry I'm a newbie with databases. All help will be appreciated thank you!
2
votes
6answers
2k views

SELECT all rows with sequential id after a specific id

Is it possible to query all rows that their ids are sequential after a specific id? (id is an AUTO_INCREMENT column.) For example, suppose my specific id is 5. Then I want all rows with these ids: ...
0
votes
1answer
24 views

Counting entries of a unique entry of another field and concatenate the result with the unique field in a new column [closed]

I want to create a query that will search the table and find the following: If a POL_N entry has ENDO_N entries then the COUNT ENDO_N field will start counting the ENDO_N entries and will get the ...
-2
votes
2answers
356 views

Adding sequence number to existing rows based on ID and Date in PLSQL Oracle [closed]

I want to add a sequence number (SEQNO) based on their REFNO and STARTD.
1
vote
0answers
111 views

Sequence: last_value billions bigger that actual count of rows

In my PostgreSQL 9.6 database, INSERT on a certain table is not possible anymore: The primary key column is an integer and the last_value of the sequence in question is 2,147,484,010 - which is too ...
3
votes
2answers
238 views

Max number of sequence objects

At my job we have a lot of objects that we track versions of. We are tentatively looking at creating a rather large number of sequence objects in order to keep track of these version. My concern is ...
2
votes
2answers
640 views

Oracle sequences equivalent in MySQL

I did ask same question on stackoverflow, but no response, hence I thought database experts will help me to solve this. I have following table similar to Oracle user_sequences. I have logic of ...
0
votes
1answer
181 views

Database Blocking [closed]

We have been using SQL Server 2014 Enterprise Edition for one of our applications and have been experiencing severe blocking the past few days. This application is supported by a vendor and hence we ...
1
vote
0answers
347 views

Can I make a sequence skip certain values?

In SQL server 2014 we are using sequences for some integer surrogate keys. They begin in the negative values counting up. Can we program the sequence to skip zero when the time comes? The reason is ...
3
votes
1answer
2k views

Postgres, how insert “0” value into serial?

I have a serial id in my application table. However, I would like to insert a single 0 id record to mean global. Is there a way I can insert this into my table without affecting the counter?
3
votes
2answers
682 views

How to retain the current value of a sequence when copying a database in SQL Server

I have a template database that contains tables with some data I'd like to have always when starting a new project. The idea is to copy the template when starting a new project. I use sequences for ...
1
vote
0answers
39 views

Oracle streams how exclude chages in sequences in schema replication

I have two DBs I want to synchronize using streams So I followed N-way replication guide. I have following config: BEGIN DBMS_STREAMS_ADM.ADD_SCHEMA_RULES( schema_name => '...
1
vote
1answer
1k views

Custom Sequence using Trigger & Sequence in Oracle SQL

I have a trigger which inserts a custom Sequence after every Parent Item is inserted. Now I have a sub-Item which is linked to the Parent Item through Parent Item Id (Sequence and Parent Item Id are 2 ...
5
votes
2answers
2k views

How can I change the sequence_name parameter after renaming a sequence (PostgreSQL)

I have renamed a sequence with the following command: ALTER SEQUENCE TableIdSeq RENAME TO NewTableIdSeq; however, when I issue the \d NewTableIdSeq command, I get the following output: ...
11
votes
4answers
3k views

What can go wrong using the same sequence across multiple tables in postgres?

We are considering using a shared sequence to assign ids to primary keys for all of the tables in our database. There are about 100 of them. Only a couple are inserted to frequently and regularly. We ...
0
votes
1answer
8k views

How to fix all duplicate key value violates unique constraint

I have a Postgres database that I created with a Django application. When I transferred it over, it never reindexed anything and it gives me errors trying to do this. It seems as if there are lots of ...
11
votes
1answer
16k views

PostgreSQL - Truncate a table on cascade and reset all hierarchic sequences with 1

Is there any way to reset all the sequences of tables, when truncate a table on cascade. I already read this post How to reset sequence in postgres and fill id column with new data? ALTER SEQUENCE ...
1
vote
1answer
492 views

Error granting access to sequence with PostgreSQL 8.4

I'm attempting to run this query GRANT USAGE ON [db].users_uid_seq TO [user]; db and user are redacted (obviously). I get this error: ERROR: syntax error at or near "GRANT" I've tried a number ...
2
votes
2answers
1k views

Custom Sequences with SQL Server

What is the best method to generate a Custom Auto-Generated Sequence with SQL Server? Here is my requirement: My application is hosted on 10 independent servers which are not interconnected. Each ...
1
vote
1answer
136 views

Number Sequence With Gaps

In an Oracle PLSQL function I want to generate a special kind of sequence number. It starts with 00000001, but when 00899999 is reached, I want to have 01000001 as its next number. This pattern ...
5
votes
3answers
5k views

How to determine which tables use a sequence in SQL Server

I have a sequence in a SQL Server 2012 database that appears in sys.sequences. How do I determine which tables use this sequence? I do not have sufficient permissions to view the definition of this ...
6
votes
2answers
7k views

postgres sequence problems, manually created pids, and proper sequence resetting

Developers encountered issues with sequences in our postgres 9.6 database over the past year, where they stop working, so they have resorted to things like inserting rows with a pid manually created ...
1
vote
3answers
1k views

Auto-incremented ID with sequence and trigger: How to handle manual overrides (causing non-unique error)

I have a sequence and trigger that provide auto-incrementing IDs to a PROJECT_ID column: PROJECTS +------------+-----+ | PROJECT_ID | ... | +------------+-----+ | LC000001 | | | LC000002 | ...
0
votes
1answer
31 views

SQL Server 2012 - Know when a SEQUENCE has recycled or is nearing cycle phase

In SQL Server 2012, is there a way to know if a Sequence has recycled? Or some sort of trigger to know if a Sequence is nearing its cycling phase. I need to update a table whenever a ...
4
votes
1answer
15k views

INSERT INTO table FROM SELECT * with nextval() specification

I need to copy records within the same table changing only one field. My table has default-generated sequence entry_id_seq, however I am not sure id column is SERIAL (how to check that?). \d tab ...
0
votes
1answer
3k views

How do i assign a custom id using a trigger using sequence on a table

i want to modify my current table which is currently generating id's using a trigger from 1 using sequence_name.nextval to something like DON-100 or REC-124 etc.I have seen some examples doing this ...