database-sequence

Add auto increment column to existing table ordered by date

狂风中的少年 提交于 2021-02-18 11:57:08
问题 I have an existing table named "tickets" in database with columns: id (string, Primary Key, contains UUID like e6c49164-545a-43a1-845f-73c5163962f2) date (biginteger, stores epoch) status (string) I need to add new auto increment column ticket_id but the values to be generated should be according to "date" column value. I tried this: ALTER TABLE "tickets" ADD COLUMN "ticket_id" SERIAL; The problem is, it is generating "ticket_id" values in some weird order, looks like it is based on "id"

Add auto increment column to existing table ordered by date

给你一囗甜甜゛ 提交于 2021-02-18 11:57:07
问题 I have an existing table named "tickets" in database with columns: id (string, Primary Key, contains UUID like e6c49164-545a-43a1-845f-73c5163962f2) date (biginteger, stores epoch) status (string) I need to add new auto increment column ticket_id but the values to be generated should be according to "date" column value. I tried this: ALTER TABLE "tickets" ADD COLUMN "ticket_id" SERIAL; The problem is, it is generating "ticket_id" values in some weird order, looks like it is based on "id"

Sequence does not exist when it does - Postgres/Spring Boot

有些话、适合烂在心里 提交于 2020-05-23 10:32:10
问题 I am writing a Spring Boot web-app and using a Postgres db to persist my data. I created a table in Postgres using create table user (id bigserial primary key not null, name text not null; and identified its sequence_name by looking at the schema (in this case, it is user_id_seq ). Then, in my User entity class in Spring Boot, I added the following: @Entity @Table(name = "user") public class User implements Serializable { @Id @SequenceGenerator(name = "user_local_seq", sequenceName = "user_id

Oracle 12.2 - Replacement of NOPARTITION feature

两盒软妹~` 提交于 2020-01-14 22:54:32
问题 I have Oracle version 12.2.0.1.0 We have generic script which create sequence that need to be reuse for different objects (by renaming sequence name): CREATE SEQUENCE NAME_SEQ MINVALUE 1 MAXVALUE 999999999 INCREMENT BY 1 START WITH 100 CACHE 200 NOORDER NOCYCLE NOPARTITION ; This script isn't working with below error until I remove NOPARTITION : ORA-00933: SQL command not properly ended I found in AskTom that the NOPARTITION is not supported in 12.2 there's been various of things in previous

postgres how to reset or update index(sequence) of table

℡╲_俬逩灬. 提交于 2020-01-06 15:01:48
问题 i deleted 2000 row in my table and then i inserted same 2000 records but their index(id auto increment field) starting from 2001, now i want to update those index 2001 - 4000 to 1-2000 回答1: To update your id run the following command. UPDATE table SET id = id - 2000; This will update the id of records in your table and then you need update the table's sequence ALTER SEQUENCE table_id_seq RESTART WITH 2001; This will allow you to insert the data with the id 2001 Another way, delete all the

postgres how to reset or update index(sequence) of table

痞子三分冷 提交于 2020-01-06 15:01:39
问题 i deleted 2000 row in my table and then i inserted same 2000 records but their index(id auto increment field) starting from 2001, now i want to update those index 2001 - 4000 to 1-2000 回答1: To update your id run the following command. UPDATE table SET id = id - 2000; This will update the id of records in your table and then you need update the table's sequence ALTER SEQUENCE table_id_seq RESTART WITH 2001; This will allow you to insert the data with the id 2001 Another way, delete all the

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

馋奶兔 提交于 2019-12-25 04:07:54
问题 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 ) ; CREATE SEQUENCE Bill_ID_SEQ START WITH 1 NOCACHE ORDER ; CREATE OR REPLACE TRIGGER Bill_ID_TRG BEFORE INSERT ON Paragony FOR EACH ROW BEGIN :NEW.ID := Bill_ID_SEQ.NEXTVAL; END; I have to use it with Django ORM so I have run inspectdb command. It is the autogenerated code:

How to implement multidimensional sequences

 ̄綄美尐妖づ 提交于 2019-12-19 10:28:06
问题 For example, here is a yearly sequence. The no increments with year : | no | year | +----+------+ | 1 | 2016 | | 2 | 2016 | | 3 | 2016 | | 1 | 2017 | | 2 | 2017 | | 4 | 2016 | For now I have created sequence for each year but the problem is Oracle will not automatically create new sequence in next year. Another problem is if I want to use a 3D sequence, incrementing within year and type : | no | year | type | +----+------+------+ | 1 | 2016 | a | | 2 | 2016 | a | | 1 | 2016 | b | | 1 | 2017 |

Postgres insert value from insert in other table

岁酱吖の 提交于 2019-12-13 17:31:27
问题 I have two tables: CREATE TABLE tbl_a ( id serial primary key NOT NULL, name text NOT NULL, tbl_b_reference NOT NULL ) CREATE TABLE tbl_b ( id serial primary key NOT NULL, status text) I want to do two inserts. One in tbl_b, and then use the id from that insert when I do my insert into tbl_a. I've tried this: INSERT INTO tbl_a(name, tbl_b_reference) VALUES ("myName", (INSERT INTO tbl_b (status) VALUES ('OK') RETURNING id)); but I only get a syntax error pointing at the second "INTO" ERROR:

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

好久不见. 提交于 2019-12-01 14:04:27
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 Your question is unclear. Please describe requirements more datailed. I understand you want to have a few sequences and increment them conditionally so: create sequence chanel1_seq INCREMENT BY 1 START WITH 1; create sequence chanel2_seq INCREMENT BY 1 START WITH 1; create sequence chanel3_seq INCREMENT BY 1 START WITH 1; and then access sequence set by function not