auto-increment

How to use time-series with Sqlite, with fast time-range queries?

元气小坏坏 提交于 2021-01-18 05:30:28
问题 Let's say we log events in a Sqlite database with Unix timestamp column ts : CREATE TABLE data(ts INTEGER, text TEXT); -- more columns in reality and that we want fast lookup for datetime ranges, for example: SELECT text FROM data WHERE ts BETWEEN 1608710000 and 1608718654; Like this, EXPLAIN QUERY PLAN gives SCAN TABLE data which is bad, so one obvious solution is to create an index with CREATE INDEX dt_idx ON data(ts) . Then the problem is solved, but it's rather a poor solution to have to

MySQL: Why does my INSERT statement skip 56 numbers when auto-incrementing the id?

自闭症网瘾萝莉.ら 提交于 2021-01-15 19:16:04
问题 While demonstrating the INSERT statement to the students of my SQL course, we've come up on some odd behavior in MySQL 8.0. Please help us learn what is happenning. (No need for workarounds as we're aware of a few and this is for learning, not for production. Thank you) We are creating a new database and copying some rows from the well-known Sakila sample DB, like so: CREATE DATABASE simpsons; USE simpsons; CREATE TABLE `character` ( character_id smallint unsigned NOT NULL AUTO_INCREMENT,

MySQL: Why does my INSERT statement skip 56 numbers when auto-incrementing the id?

佐手、 提交于 2021-01-15 19:14:48
问题 While demonstrating the INSERT statement to the students of my SQL course, we've come up on some odd behavior in MySQL 8.0. Please help us learn what is happenning. (No need for workarounds as we're aware of a few and this is for learning, not for production. Thank you) We are creating a new database and copying some rows from the well-known Sakila sample DB, like so: CREATE DATABASE simpsons; USE simpsons; CREATE TABLE `character` ( character_id smallint unsigned NOT NULL AUTO_INCREMENT,

MySQL: Why does my INSERT statement skip 56 numbers when auto-incrementing the id?

青春壹個敷衍的年華 提交于 2021-01-15 19:12:58
问题 While demonstrating the INSERT statement to the students of my SQL course, we've come up on some odd behavior in MySQL 8.0. Please help us learn what is happenning. (No need for workarounds as we're aware of a few and this is for learning, not for production. Thank you) We are creating a new database and copying some rows from the well-known Sakila sample DB, like so: CREATE DATABASE simpsons; USE simpsons; CREATE TABLE `character` ( character_id smallint unsigned NOT NULL AUTO_INCREMENT,

MySQL: Why does my INSERT statement skip 56 numbers when auto-incrementing the id?

别来无恙 提交于 2021-01-15 19:10:29
问题 While demonstrating the INSERT statement to the students of my SQL course, we've come up on some odd behavior in MySQL 8.0. Please help us learn what is happenning. (No need for workarounds as we're aware of a few and this is for learning, not for production. Thank you) We are creating a new database and copying some rows from the well-known Sakila sample DB, like so: CREATE DATABASE simpsons; USE simpsons; CREATE TABLE `character` ( character_id smallint unsigned NOT NULL AUTO_INCREMENT,

Change mysql auto increment id column value

浪尽此生 提交于 2021-01-07 03:52:23
问题 I have a mysql table with an gpid AUTO_INCREMENT NOT NULL UNIQUE column. After filling this table (which has 50M+ entries), I have realized that mysql still increments AUTO_INCREMENT columns if transaction fails because of an IntegrityError, and understandably so. The results are gaps in AUTO_INCREMENT columns, with gpid jumping values (for exemple from gpid == 3 to gpid == 5 between two consecutive rows). While this is not an issue for machines, it is one for my coworkers and I. The purpose

Auto increment django model field per user

…衆ロ難τιáo~ 提交于 2020-12-30 06:36:05
问题 I have this model: class Invoice(models.Model): owner = models.ForeignKey(settings.AUTH_USER_MODEL) data = models.TextField(default=None, blank=True, null=True) number = models.PositiveIntegerField(default=0, null=False) What I need is to auto-increment the field number for each separated user. The rationale is that each user has a list of Invoice , starting from number=1 to number=latest.number+1 . I do known about F() expressions, but can't figure out how to reference the latest/greatest

MongoDB auto increment ID with PHP

倖福魔咒の 提交于 2020-12-15 04:58:42
问题 currently i'm using this php code to create my own auto increment ID in MongoDB. $mongo = new MongoDB\Driver\Manager("mongodb://10.1.1.111:27017"); $find = [ '_id' => 'campaignid' ]; $query = new MongoDB\Driver\Query($find, [ ]); $rows = $mongo->executeQuery('testdb.counters', $query); $arr = $rows->toArray(); $oldId = 0; if(count($arr) > 0) { $old = array_pop($arr); $oldId = intval($old->seq); } $nextId = ++$oldId; $set = [ '_id' => 'campaignid', 'seq' => $nextId ]; $insRec = new MongoDB

MongoDB auto increment ID with PHP

删除回忆录丶 提交于 2020-12-15 04:57:17
问题 currently i'm using this php code to create my own auto increment ID in MongoDB. $mongo = new MongoDB\Driver\Manager("mongodb://10.1.1.111:27017"); $find = [ '_id' => 'campaignid' ]; $query = new MongoDB\Driver\Query($find, [ ]); $rows = $mongo->executeQuery('testdb.counters', $query); $arr = $rows->toArray(); $oldId = 0; if(count($arr) > 0) { $old = array_pop($arr); $oldId = intval($old->seq); } $nextId = ++$oldId; $set = [ '_id' => 'campaignid', 'seq' => $nextId ]; $insRec = new MongoDB

SQLite starting rowid of 0

≯℡__Kan透↙ 提交于 2020-12-13 10:35:53
问题 I'm trying to set up a SQLite table where the rowid starts from 0 instead of the default 1. The end goal is to be able to run the first INSERT statement and have it insert to rowid 0. Explicitly setting rowid to 0 for that first INSERT is not an option. I've tried a few things related to AUTOINCREMENT but am not having any luck getting this to work cleanly. The only successful way I've found is to insert a row with rowid of -1 and then delete it later. This works but it's messy and I'd like