duplicates

SQL Performance - Better to Insert and Raise Exception or Check exists?

狂风中的少年 提交于 2019-12-23 12:23:47
问题 I'm considering an optimisation in a particularly heavy part of my code. It's task is to insert statistical data into a table. This data is being hit a fair amount by other programs. Otherwise I would consider using SQL Bulk inserts etc. So my question is... Is it ok to try and insert some data knowing that it might (not too often) throw a SqlException for a duplicate row? Is the performance hit of an exception worse than checking each row prior to insertion? 回答1: First, my advice is to err

Why doesn't this array_unique work as expected?

♀尐吖头ヾ 提交于 2019-12-23 12:23:40
问题 Can anybody tell me why this doesn't work as expected? <?php $merchant_string = '123-Reg|Woolovers|Roxio|Roxio|BandQ|Roxio|Roxio|Big Bathroom Shop|Roxio|Robert Dyas|Roxio|Roxio|PriceMinister UK|Cheap Suites|Kaspersky|Argos|Argos|SuperFit|PriceMinister UK|Roxio|123-Reg'; $merchant_array = explode('|', $merchant_string); for($i = 0; $i<count($merchant_array); $i++) { $merchant_array = array_unique($merchant_array); echo $merchant_array[$i] . '<br />'; } ?> The results I get is: Woolovers Roxio

Delete “duplicate” rows in SQL Server 2010

被刻印的时光 ゝ 提交于 2019-12-23 09:49:18
问题 I made a mistake in a bulk insert script, so now i have "duplicate" rows with different colX. I need to delete this duplicate rows, but I cant figure out how. To be more precise, I have this: col1 | col2 | col3 | colX ----+---------------------- 0 | 1 | 2 | a 0 | 1 | 2 | b 0 | 1 | 2 | c 0 | 1 | 2 | a 3 | 4 | 5 | x 3 | 4 | 5 | y 3 | 4 | 5 | x 3 | 4 | 5 | z and I want to keep the first occurrence of each (row, colX): col1 | col2 | col3 | colX ----+---------------------- 0 | 1 | 2 | a 3 | 4 | 5

Underscore.js, remove duplicates in array of objects based on key value

∥☆過路亽.° 提交于 2019-12-23 09:33:01
问题 I have the following JS array: var myArray = [{name:"Bob",b:"text2",c:true}, {name:"Tom",b:"text2",c:true}, {name:"Adam",b:"text2",c:true}, {name:"Tom",b:"text2",c:true}, {name:"Bob",b:"text2",c:true} ]; I want to eliminate the indexes with name value duplicates and recreate a new array, with distinct names, eg: var mySubArray = [{name:"Bob",b:"text2",c:true}, {name:"Tom",b:"text2",c:true}, {name:"Adam",b:"text2",c:true}, ]; As you can see, I removed "Bob" and "Tom", leaving only 3 distinct

Return FALSE for duplicated NA values when using the function duplicated()

纵饮孤独 提交于 2019-12-23 09:19:29
问题 just wondering why duplicated behaves the way it does with NAs: > duplicated(c(NA,NA,NA,1,2,2)) [1] FALSE TRUE TRUE FALSE FALSE TRUE where in fact > NA == NA [1] NA is there a way to achieve that duplicated marks NAs as false, like this? > duplicated(c(NA,NA,NA,1,2,2)) [1] FALSE FALSE FALSE FALSE FALSE TRUE 回答1: You use the argument incomparables for the function duplicated like this : > duplicated(c(NA,NA,NA,1,2,2)) [1] FALSE TRUE TRUE FALSE FALSE TRUE > duplicated(c(NA,NA,NA,1,2,2)

Create duplicate rows based on conditions in R

廉价感情. 提交于 2019-12-23 07:29:17
问题 I have a data.table that looks like this dt <- data.table(ID=c("A","A","B","B"),Amount1=c(100,200,300,400), Amount2=c(1500,1500,2400,2400),Dupl=c(1,0,1,0)) ID Amount1 Amount2 Dupl 1: A 100 1500 1 2: A 200 1500 0 3: B 300 2400 1 4: B 400 2400 0 I need to duplicate each row that has a 1 in the Dupl column and replace the Amount1 value with the Amount2 value in that duplicated row. Besides that I need to give that duplicated row the value 2 in Dupl. This means it should look like this: ID

Preventing Duplicate List<T> Entries

半腔热情 提交于 2019-12-23 07:09:08
问题 I expect I'll be able to make a work around but I can't for the life of me understand why this code is not functioning correctly and allowing duplicate entries to be added to the List. The if statement condition is never met, even when I drag identical files in from the same location. I don't understand why the "Contains" method isn't matching them up. public class Form1:Form { private List<FileInfo> dragDropFiles = new List<FileInfo>(); private void Form1_DragDrop(object sender,

How to Remove Duplicate Matches in a MatchCollection

吃可爱长大的小学妹 提交于 2019-12-23 07:04:29
问题 In my MatchCollection, I get matches of the same thing. Like this: string text = @"match match match"; Regex R = new Regex("match"); MatchCollection M = R.Matches(text); How does one remove duplicate matches and is it the fastest way possible? Assume "duplicate" here means that the match contains the exact same string. 回答1: Linq If you are using .Net 3.5 or greater such as 4.7, linq can be used to remove the duplicates of the match. string data = "abc match match abc"; Console.WriteLine

How to Remove Duplicate Matches in a MatchCollection

 ̄綄美尐妖づ 提交于 2019-12-23 07:04:29
问题 In my MatchCollection, I get matches of the same thing. Like this: string text = @"match match match"; Regex R = new Regex("match"); MatchCollection M = R.Matches(text); How does one remove duplicate matches and is it the fastest way possible? Assume "duplicate" here means that the match contains the exact same string. 回答1: Linq If you are using .Net 3.5 or greater such as 4.7, linq can be used to remove the duplicates of the match. string data = "abc match match abc"; Console.WriteLine

Java random numbers with no duplicates for a lottery using methods and arrays [duplicate]

 ̄綄美尐妖づ 提交于 2019-12-23 05:49:05
问题 This question already has answers here : Java Random number with no duplicate [duplicate] (5 answers) Closed last year . For my computer science class we're supposed to redo a lottery code we have already created, but now using methods and arrays. This is what I've done so far, but I can't figure out for the life of me why it is still duplicating the numbers and I can't find anything online that is close enough to what we're supposed to be doing/topics we have gone over. I am very new to this