auto-increment

currval has not yet been defined this session, how to get multi-session sequences?

人走茶凉 提交于 2019-12-20 11:06:51
问题 My objective is to get a primary key field automatically inserted when inserting new row in the table. How to get a sequence going from session to session in PostgreSQL? doubleemploi@hanbei:/home/yves$ psql -d test Mot de passe : psql (8.4.13) Saisissez « help » pour l''aide. test=> create sequence test001 start 10; CREATE SEQUENCE test=> select currval('test001'); ERREUR: la valeur courante (currval) de la séquence « test00 » n''est pas encore définie dans cette session --- current value not

Compact or renumber IDs for all tables, and reset sequences to max(id)?

走远了吗. 提交于 2019-12-20 10:54:48
问题 After running for a long time, I get more and more holes in the id field. Some tables' id are int32, and the id sequence is reaching its maximum value. Some of the Java sources are read-only, so I cannot simply change the id column type from int32 to long , which would break the API. I'd like to renumber them all. This may be not good practice, but good or bad is not concerned in this question. I want to renumber, especially, those very long IDs like "61789238", "548273826529524324". I don't

C# Class Auto increment ID

∥☆過路亽.° 提交于 2019-12-20 10:09:48
问题 I am creating a class in C# called "Robot", and each robot requires a unique ID property which gives themselves an identity. Is there any way of creating an auto incremental ID for each new class object? So, If i created 5 new robots, their IDs respectively will be 1, 2, 3, 4, 5. If I then destroy robot 2 and create a new robot later, it will have the ID of 2. And if I add a 6th it will have the ID of 6 and so on.. Thanks. 回答1: This will do the trick, and operate in a nice threadsafe way. Of

How to choose between UUIDs, autoincrement/sequence keys and sequence tables for database primary keys?

為{幸葍}努か 提交于 2019-12-20 08:49:02
问题 I'm looking at the pros and cons of these three primary methods of coming up with primary keys for database rows. So assuming I am using a database that supports more than one of these methods, is there a simple heuristic to determine what the best option would be for me? How do considerations such a distributed/multiple masters, performance requirements, ORM use, security and testing have on the choice? Any unexpected drawbacks that one might run into? 回答1: UUIDs Unless these are generated

Some sort of “different auto-increment indexes” per a primary key values

廉价感情. 提交于 2019-12-20 04:59:15
问题 I have got a table which has an id (primary key with auto increment), uid (key refering to users id for example) and something else which for my question won’t matter. I want to make, lets call it, different auto-increment keys on id for each uid entry. So, I will add an entry with uid 10, and the id field for this entry will have a 1 because there were no previous entries with a value of 10 in uid . I will add a new one with uid 4 and its id will be 3 because I there were already two entried

MySQL table with AUTO_INCREMENT primary id does not release the number after a rollback

南笙酒味 提交于 2019-12-20 04:56:14
问题 I have a table with bills. Every bill has an id that comes from the DB after I insert a new record. The field is an INTEGER with AUTO_INCREMENT set. If I insert a new record as part of a transaction and I have to rollback this transaction, the ID is taken and gone. So the next record becomes the ID one higher, even though this ID is not in use. It would be better for the bills to have a linear numbering, so the accounting can figure out if something is wrong. 回答1: For concurrency reasons, the

Custom auto-increment field in postgresql (Invoice/Order No.)

不羁岁月 提交于 2019-12-20 03:35:12
问题 The baseline requirement is to create an order number in the format: (M)M-SSS Where MM represents the current month and SSSS represents the order sequence for that month. For example 1-002 would represent the second order submitted in January. Using a TRIGGER I'd like the auto-increment and insert to work transparently. Unfortunately, it has been a long time since I have touched a stored procedure and this is my first foray into postgresql. Any help pointing in the right direction would be

When to fix auto-increment gaps in MYSQL

六月ゝ 毕业季﹏ 提交于 2019-12-20 03:19:48
问题 The database I am working on right now has records being added and removed by the 10s of thousands and because of this there are gaps in the auto-incremented key hundreds of thousands big and auto-increment numbers well into the billions. These numbers are never stored to reference the individual record but are used to reference the record when doing on-the-fly calculations. Is there any reason to remove these gaps and reset the auto-increment number or is this inconsequential? The id field

Autoincrement ID in App Engine datastore

柔情痞子 提交于 2019-12-20 02:47:13
问题 I'm using App Engine datastore, and would like to make sure that row IDs behave similarly to "auto-increment" fields in mySQL DB. Tried several generation strategies, but can't seem to take control over what happens: the IDs are not consecutive, there seem to be several "streams" growing in parallel. the ids get "recycled" after old rows are deleted Is such a thing at all possible ? I really would like to refrain from keeping (indexed) timestamps for each row. 回答1: It sounds like you can't

MySQL auto increment ID suddenly jumped to MAXINT, what could be a reason?

戏子无情 提交于 2019-12-20 01:59:06
问题 I have a mysql table with about 2,000,000 entries, with a primary key which is auto incrementing. However, at one point the auto increment value suddenly jumped from what it was (around 2,000,000) to maximum integer value (2,147,483,647). Needless to say all subsequent insertions into this table failed. When I noticed it, I changed primary key type from int to bigint and so it works fine for now. So my question is, why could this have happened? And are there any precautions which I could take