sequences

MySql autoincrement column increases by 10 problem

I am a user of a some host company which serves my MySql database. Due to their replication problem, the autoincrement values increses by 10, which seems to be a common problem. My question is how can I simulate (safely) autoincrement feature so that the column have an consecutive ID? My idea was to implement some sequence mechanism ...

How bad is it to simulate IDENTITY/AUTOINCREMENT columns using triggers in Oracle?

I maintain an application that was originally written to be SQL Server-specific (using IDENTITY fields). Thus, we've had to define a lot of triggers to auto increment tables' primary keys. I'm told that this is considered to be a hacky workaround in the Oracle world, but that was told to me in a "friend of a friend" kind of way. How b...

How do I solve an arithmetic sequence?

How does: (1 + 2 + ... + N) / N = (N + 1) / 2 or (1 + 2 + ... + N + N) / N = (N + 3) / 2 My textbook says this is elementary math but I have forgotten the method for finding the answer. ...

Oracle OCI trigger creation

Is there any way to create trigger using OCI API? I need to perform the following actions programmatically: CREATE OR REPLACE TRIGGER tbl_trigger BEFORE INSERT ON tbl FOR EACH ROW WHEN (new.id IS NULL OR new.id = 0) BEGIN SELECT tbl_sq.nextval INTO :new.id FROM dual; END; / ...

How do you get N(N+1) from N+1 + N + 1 + ... + N + 1 + N + 1?

How does: 1 + 2 + ... + N-1 + N + N + N-1 + ... + 2 + 1 --------------------------- N+1 + N+1 + ... + N+1 + N+1 equal N(N + 1)? Shouldn't it be 4N + 4 or 4(N + 1)? ...

How can I extend std::basic_streambuf to treat any iterable sequence as a stream?

Note: Edited based on responses to receive more appropriate answers. I have a collection of C++ templates that I've made over the years, which I call Joop. It comprises mainly libraries that don't quite fall into the "general-purpose" category but are just useful enough that I keep slapping them into different projects, so most of them ...

What's the alternate character combination for the double quote characater in C/C++?

I've not had the Kernighan and Ritchie C reference in years, but I remember that there was a page in there that talked about how to enter characters that were unavailable to you. (WAY back in the day, some keyboards lacked characters like ", ~, etc.) To be clear, let me give an example. I'm not looking for a way to get quotes in strin...

Ruby equivalent of C#'s 'yield' keyword, or, creating sequences without preallocating memory

In C#, you could do something like this: public IEnumerable<T> GetItems<T>() { for (int i=0; i<10000000; i++) { yield return i; } } This returns an enumerable sequence of 10 million integers without ever allocating a collection in memory of that length. Is there a way of doing an equivalent thing in Ruby? The specifi...

MySQL id sequence

Is this a correct way for id generation in MySQL ? INSERT INTO Picture (PictureId,First_pick,Title,Description,File_Name,Is_Vertical)VALUES ((SELECT max(pictureid)+1 FROM Picture),0,?,?,?,?) I mean if it is guaranted that PictureId will be unique when this query is run by many threads ? I can't modify table structure. Should I...

Implementing __concat__ in Python

I tried to implement __concat__, but it didn't work >>> class lHolder(): ... def __init__(self,l): ... self.l=l ... def __concat__(self, l2): ... return self.l+l2 ... def __iter__(self): ... return self.l.__iter__() ... >>> lHolder([1])+[2] Traceback (most recent call last): File "<stdi...

Is there a functional way to do this?

def flattenList(toFlatten): final=[] for el in toFlatten: if isinstance(el, list): final.extend(flattenList(el)) else: final.append(el) return final When I don't know how deeply the lists will nest, this is the only way I can think to do this. ...

Django + Postgres: How to specify sequence for a field

I have this model in django: class JournalsGeneral(models.Model): jid = models.AutoField(primary_key=True) code = models.CharField("Code", max_length=50) name = models.CharField("Name", max_length=2000) url = models.URLField("Journal Web Site", max_length=2000, blank=True) online = models.BooleanField("Online?") ...

Postgresql: keep 2 sequences synchronized

Is there a way to keep 2 sequences synchronized in Postgres? I mean if I have: table_A_id_seq = 1 table_B_id_seq = 1 if I execute SELECT nextval('table_A_id_seq'::regclass) I want that table_B_id_seq takes the same value of table_A_id_seq and obviously it must be the same on the other side. I need 2 different sequences because I ...

Trying to generate all sequences of specified numbers up to a max sum

Hi, Given the following list of descending unique numbers (3,2,1) I wish to generate all the sequences consisting of those numbers up to a maximum sum. Let's say that the sum should be below 10. Then the sequences I'm after are: 3 3 3 3 3 2 1 3 3 2 3 3 1 1 1 3 3 1 1 3 3 1 3 3 3 2 2 2 3 2 2 1 1 3 2 2 1 3 2 2 3 2 1 1 1 1 3 2 1 1 1 3 2 1...

The difference between lists and sequences

I'm trying to understand the difference between sequences and lists. In F# there is a clear distinction between the two. However in C# I have seen programmers refer to IEnumerable collections as a sequence. Is what makes IEnumerable a sequence the fact that it returns an object to iterate through the collection? Perhaps the real distin...

Distributed sequence number generation?

I've generally implemented sequence number generation using database sequences in the past. e.g. Using Postgres SERIAL type http://neilconway.org/docs/sequences/ I'm curious though as how to generate sequence numbers for large distributed systems where there is no database. Does anybody have any experience or suggestions of a best pra...

Sharing activerecord classes between oracle and ms sql server.

I have primary key sequence for oracle in my Castle ActiveRecord class: [PrimaryKey(PrimaryKeyType.SeqHiLo, "UserId", SequenceName = "users_seq")] public int Id { get; set; } Now i need to configure ActiveRecord to use Sql Server, but it does not support sequences, but it's not possible, since oracle-specific mapping is used. I don't...

How to create a sql function using temp sequences and a SELECT on PostgreSQL8

Hello there, I have this issue in either postgreSQL 8.3 or 8.4: I've created a script which (re)creates three temp sequences and then uses them to transpose some tables in order to get a single row. Now I want to put it in a FUNCTION which returns a type already created (I've done a select into and then I took the fields from the creat...

Repeating vectors in Clojure

There has got to be a better way. I am a Clojure newbie. I am trying to get two copies of a vector of card suits. The non-DRY way that I can come up with is (def suits [:clubs :diamonds :hearts :spades]) (def two-times (concat suits suits)) There must be a more functional way (even if it takes more characters :-)). What if i want N t...

How to insert an n:m-relationship with technical primary keys generated by a sequence?

Let's say I have two tables with several fields and in every table there is a primary key which is a technical id generated by a database sequence: table1 table2 ------------- ------------- field11 <pk> field21 <pk> field12 field22 field11 and field21 are generated by sequences. Also there is a n:...