sequences

How can I determine the actual database row insertion order?

∥☆過路亽.° 提交于 2019-12-10 19:23:52
问题 I have a multithreaded process which inserts several records into a single table. The inserts are performed in a stored procedure, with the sequence being generated INTO a variable, and that variable is later used inside of an INSERT . Given that I'm not doing mysequence.nextval inside the INSERT itself, it makes me think that it is possible for two concurrent processes to grab a sequence in one order, then do the inserts in the reverse order. If this is the case, then the sequence numbers

Numbers in Geometric Progression

China☆狼群 提交于 2019-12-10 12:33:16
问题 How can i generate a sequence of numbers which are in Geometric Progression in R? for example i need to generate the sequence : 1, 2,4,8,16,32 and so on....till say a finite value? 回答1: Here's what I'd do: geomSeries <- function(base, max) { base^(0:floor(log(max, base))) } geomSeries(base=2, max=2000) # [1] 1 2 4 8 16 32 64 128 256 512 1024 geomSeries(3, 100) # [1] 1 3 9 27 81 回答2: Why not just enter 2^(0:n)? E.g. 2^(0:5) gets you from 1 to 32 and so on. Capture the vector by assigning to a

How do you get the next value in a sequence into a variable?

谁说胖子不能爱 提交于 2019-12-09 17:28:30
问题 So I'm writing a stored procedure and am having trouble getting the next value of a sequence into a variable. The sequence name is passed into the function and is stored as a varchar2 variable. How can you get the next value in that sequence into a local variable. 回答1: Something like this? create or replace procedure next_val (p_sequence_name varchar2) as v_nextval integer; v_select varchar2(100); begin v_select := 'select '||p_sequence_name||'.nextval from dual'; execute immediate v_select

Deleting a table in PostgreSQL without deleting an associated sequence

江枫思渺然 提交于 2019-12-09 14:50:06
问题 I have a table, foo . For the purposes of a quick upgrade/deploy of my site, I made a new table, tmp_foo , to contain some new data, by doing: create table tmp_foo (like foo including constraints including defaults including indexes); Now each table has a PK id column that looks like: Column | Type | Modifiers -------------+-----------------------+-------------------------------------------------------------------------- id | integer | not null default nextval('foo_id_seq'::regclass) The

Fixing holes/gaps in numbers generated by Postgres sequence

99封情书 提交于 2019-12-08 22:31:10
问题 I have a postgres database that uses sequences extensively to generate primary keys of tables. After a lot of usage of this database i.e. Adding/Update/Delete operation the columns that uses sequences for primary keys now have a lot holes/gaps in them and the sequence value itself is very high. My question is: Are there any ways in which we can fix these gaps in Primary Keys? which should inturn bring down the max value of the number in that columns and then reset the sequence? Note: A lot of

LSTM Sequence Prediction in Keras just outputs last step in the input

倾然丶 夕夏残阳落幕 提交于 2019-12-07 23:31:59
问题 I am currently working with Keras using Tensorflow as the backend. I have a LSTM Sequence Prediction model shown below that I am using to predict one step ahead in a data series (input 30 steps [each with 4 features], output predicted step 31). model = Sequential() model.add(LSTM( input_dim=4, output_dim=75, return_sequences=True)) model.add(Dropout(0.2)) model.add(LSTM( 150, return_sequences=False)) model.add(Dropout(0.2)) model.add(Dense( output_dim=4)) model.add(Activation("linear")) model

Longest common contiguous subsequence - algorithm

↘锁芯ラ 提交于 2019-12-07 18:09:06
问题 My question is simple: Is there an O(n) algorithm for finding the longest contiguous subsequence between two sequences A and B? I searched it, but all the results were about the LCS problem, which is not what I'm seeking. Note: if you are willing to give any sample code, you are more than welcome to do so, but please, if you can, in C or C++. Edit: Here is an example: A: { a, b, a, b, b, b, a } B: { a, d, b, b, b, c, n } longest common contiguous subsequence: { b, b, b } 回答1: Yes, you can do

Sequence reduction in R

最后都变了- 提交于 2019-12-07 07:30:53
问题 Assume you have a vector like so: v <- c(1,1,1,2,2,2,2,1,1,3,3,3,3) How can it be best reduced to a data.frame like this? v.df <- data.frame(value=c(1,2,1,3),repetitions=c(3,4,2,4)) In a procedural language I might just iterate through a loop and build the data.frame as I go, but with a large dataset in R such an approach is inefficient. Any advice? 回答1: or more simply data.frame(rle(v)[]) 回答2: with(rle(v), data.frame(values, lengths)) should get you what you need. values lengths 1 3 2 4 1 2

Why there is no List.skip and List.take?

无人久伴 提交于 2019-12-06 18:31:40
问题 Why there is no List.skip and List.take? There is of course Seq.take and Seq.skip, but they does not create lists as a result. One possible solution is: mylist |> Seq.skip N |> Seq.toList But this creates first enumerator then a new list from that enumerator. I think there could be more direct way to create a immutable list from immutable list. Since there is no copying of elements internally there are just references from the new list to the original one. Other possible solution (without

How can I merge two sequences in clojure?

不想你离开。 提交于 2019-12-06 16:36:36
问题 What is an idiomatic way to merge (or retrieve the union of) two lists (or sequences) in Clojure? (merge l1 l2) doesn't seem to be the solution: a=> (merge '(1 2 3) '(2 3 4)) ((2 3 4) 1 2 3) 回答1: I think andih's solution works great. Here is an alternate way because hey why not. It uses concat and distinct: user> (distinct (concat '(1 2 3) '(2 3 4))) => (1 2 3 4) 回答2: One way to get the union of two lists is to use union Clojure> (into #{} (clojure.set/union '(1,2,3) '(3,4,5))) #{1 2 3 4 5}