indexing

PostgreSQL composite primary key

流过昼夜 提交于 2019-12-28 03:45:17
问题 In MySQL, when I create a composite primary key, say with columns X, Y, Z , then all three columns become indexes automatically. Does the same happen for Postgres? 回答1: If you create a composite primary key, on (x, y, z) , PostgreSQL implements this with the help of one UNIQUE multi-column btree index on (x, y, z) . In addition, all three columns are NOT NULL (implicitly), which is the main difference between a PRIMARY KEY and a UNIQUE INDEX . Besides obvious restrictions on your data, the

Index all *except* one item in python

家住魔仙堡 提交于 2019-12-28 03:29:11
问题 Is there a simple way to index all elements of a list (or array, or whatever) except for a particular index? E.g., mylist[3] will return the item in position 3 milist[~3] will return the whole list except for 3 回答1: For a list , you could use a list comp. For example, to make b a copy of a without the 3rd element: a = range(10)[::-1] # [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] b = [x for i,x in enumerate(a) if i!=3] # [9, 8, 7, 5, 4, 3, 2, 1, 0] This is very general, and can be used with all iterables,

Keyed lookup on data.table without 'with'

北城余情 提交于 2019-12-28 03:10:14
问题 I have a data.table structure like so (except mine is really huge): dt <- data.table(x=1:5, y=3:7, key='x') I want to look up rows in that structure by another variable whose name is x (notice - the same as the name of the key of dt ): x <- 3:4 dt2 <- dt[ J(x) ] This doesn't work, because the lookup sees the column name first, and the local variable is obscured: dt2 # x y # 1: 1 3 # 2: 2 4 # 3: 3 5 # 4: 4 6 # 5: 5 7 I thought about the with argument for [.data.table , but that only applies to

How to index an element of a list object in R

核能气质少年 提交于 2019-12-28 02:44:08
问题 I'm doing the following in order to import some txt tables and keep them as list: # set working directory - the folder where all selection tables are stored hypo_selections<-list.files() # change object name according to each species hypo_list<-lapply(hypo_selections,read.table,sep="\t",header=T) # change object name according to each species I want to access one specific element, let's say hypo_list[1]. Since each element represents a table, how should I procced to access particular cells

Undefined index (PHP)

谁说胖子不能爱 提交于 2019-12-25 20:28:14
问题 Need some explanation. I made form as following: <form action="test4.php" method="post"> <select name="code"> <option value="A">A</option> <option value="B">B</option> <option value="C">C</option> <option value="D">D</option> <option value="E">E</option> </select> <input type="submit" value="Cus!"> </form> Then to store value of the form to $code, I used a line of script that I found in a forum $code= empty ($_POST['code']) ? null : $_POST['code']; Actually It worked, But it was not explained

Python list of lists specific path combinations or permutations

拈花ヽ惹草 提交于 2019-12-25 19:48:10
问题 I have a list of lists and am looking for something similar to combinations or permutations, but there are conditions that may result in good "Path" or "Dead_End". If "Dead_End", it should index to the next choice in the list. Example: AList = [[1, 2, 3], [2, 0, 3], [3, 1, 0], [1, 0, 2]] N = 0 Index = 0 #AList[N][Index]=1, AList[2][2]=0 I would like to start with the value AList[N][Index], which at the start is [0][0] and therefore equals 1 and assign that to N. After N is assigned 1, we can

Mysql subquery always doing filesort

匆匆过客 提交于 2019-12-25 19:06:18
问题 I have a table gamesplatform_pricehistory with an index : ( id_app , country , dateup ) doing this explain select dateup from gamesplatform_pricehistory where id_app=1 and country=1 order by dateup desc limit 1 shows "Using where; Using index" but with a subquery : explain select app.id, (select dateup from gamesplatform_pricehistory where id_app=app.id and country=1 order by dateup desc limit 1) from app where id > 0; shows Using where; Using index; Using filesort Here is a sqlfiddle showing

In postgres how do I add index to existing table?

半腔热情 提交于 2019-12-25 18:56:15
问题 In postgres how do I add index to existing table? I tried following but it's not working: CREATE INDEX my_index ON my_table USING btree(a_column); and then this: CREATE INDEX my_index ON my_table USING btree(a_column); But neither works. I am using ant to do a db migration. And when I do ant db-migrate-apply-postgresql I keep getting the error [echo] ERROR: relation "my_index" already exists 回答1: Well, this error message: ERROR: relation "my_index" already exists is pretty clear, isn't it.

excel formula to pull values from another sheet if number in one column is the same

China☆狼群 提交于 2019-12-25 18:50:00
问题 I am trying to automate an invoice and need some help. I have my invoice formatted on one tab, and all orders are entered on a separate tab. The 'Orders' tab has multiple columns -- Invoice ID, Invoice Date, Customer ID, etc. Each product within an order is entered on a new row with the same Invoice ID. I have formulas set up in the cells on my 'Invoice' tab to grab the information from the 'Orders' tab when I simply input the Invoice ID. However, how do I modify the formula to get all the

Finding median for even length array in ruby

℡╲_俬逩灬. 提交于 2019-12-25 18:35:06
问题 I cannot figure out why I cannot get the even length portion correct. def median(array) array.sort! if array.length % 2 == 0 #if amount of array members is even (array[(array.length/2) + 1] + array[array.length/2]) / 2.to_f #return average of the 2 middle array members else #if amount of array members is odd array[array.length/2.ceil] #return middle number end end My attempt is for example, an array whose length is 6, and whose 3rd and 4th index value are 7 and 9. array[6/3+1] + array [6/3]