upsert

Drupal database API query - row.update if exists, else row.insert

谁都会走 提交于 2020-01-13 13:05:25
问题 I've been trying to run a query in drupal that'll update entries if they already exists or insert a new entry if it doesnt. The code looks like this at the moment: db_query("IF EXISTS (SELECT %d FROM {uc_posten_packages.pid}) UPDATE {uc_posten_packages} SET title = '%s', label = '%s', cost = '%d', length = '%d', width ='%d', height = '%d', weight = '%d' WHERE pid = %d ELSE INSERT INTO {uc_posten_packages} VALUES ('%d', '%s', '%s', '%d', '%d', '%d', '%d', '%d')",$id, $title, $label, $rate,

AddOrUpdate works not as expected and produces duplicates

喜欢而已 提交于 2020-01-10 21:20:27
问题 I'm using Code-First DBContext-based EF5 setup. In DbMigrationsConfiguration.Seed I'm trying to fill DB with default dummy data. To accomplish this task, I use DbSet.AddOrUpdate method. The simplest code to illustrate my aim: j = 0; var cities = new[] { "Berlin", "Vienna", "London", "Bristol", "Rome", "Stockholm", "Oslo", "Helsinki", "Amsterdam", "Dublin" }; var cityObjects = new City[cities.Length]; foreach (string c in cities) { int id = r.NextDouble() > 0.5 ? 0 : 1; var city = new City {

insert into mysql database, if records already exists, then update [duplicate]

别说谁变了你拦得住时间么 提交于 2020-01-03 02:56:37
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: How do I update if exists, insert if not (aka upsert or merge) in MySQL? how to insert into mysql database, if records already exists, then update...I know there is a solution on this page: http://dev.mysql.com/doc/refman/5.1/en/insert-on-duplicate.html sib_table +=======================================================+ | sib_id | std_id | sib_name | sib_sex | sib_age | +=========================================

When will a mongodb document expire after it is updated?

烂漫一生 提交于 2019-12-31 22:31:40
问题 I have a collections of documents in mongodb, with the expireAfterSeconds property set on a date-type index. For the sake of argument, the documents are set to expire after one hour. When I update a document in this collection, which one of the following will happen? a) The document will expire one hour after the original creation time. b) The document will expire one hour after the update time. c) The document will expire one hour after the indexed variable 's time, whatever that may be. d)

Postgres upsert: distinguish between new and updated rows [duplicate]

帅比萌擦擦* 提交于 2019-12-31 04:35:20
问题 This question already has an answer here : How can I get the INSERTED and UPDATED rows for an UPSERT operation in postgres (1 answer) Closed 8 days ago . I'm thinking of using PostgreSQL INSERT .. ON CONFLICT UPDATE functionality. Ideally I would be able to distinguish between which rows were successful inserted and which were updated. Is there a way to do it? 回答1: You need an additional auxiliary column for this ( updated in the example). create table test (id int primary key, str text,

Core Data “Upsert” from SQLite Database

久未见 提交于 2019-12-30 07:42:29
问题 I am currently writing an App that needs the ability to modify and persist various pieces of data. I've decided to use Core Data for this purpose. When the user opens the Application for the first time I need to import a large amount of data from a sqlite database, this data consists of the many-to-many relationships. I'd like to find out the best way to insert all of this data into my code data store. Right now I am using an NSOperation to do the import while that rest of the application

how to load data faster with talend and sql server

走远了吗. 提交于 2019-12-30 01:20:08
问题 I use Talend to load data into a sql-server database. It appears that the weakest point of my job is not the dataprocessing, but the effective load in my database, which is not faster than 17 rows/sec. The funny point is that I can launch 5 jobs in the same time, and they'll all load at 17rows/sec . What could explain this slowness and how could I improve the speed? Thanks New informations: The transfer speed between my desktop and the server is about 1MByte My job commits every 10 000 I use

Return rows from INSERT with ON CONFLICT without needing to update

半世苍凉 提交于 2019-12-28 13:47:10
问题 I have a situation where I very frequently need to get a row from a table with a unique constraint, and if none exists then create it and return. For example my table might be: CREATE TABLE names( id SERIAL PRIMARY KEY, name TEXT, CONSTRAINT names_name_key UNIQUE (name) ); And it contains: id | name 1 | bob 2 | alice Then I'd like to: INSERT INTO names(name) VALUES ('bob') ON CONFLICT DO NOTHING RETURNING id; Or perhaps: INSERT INTO names(name) VALUES ('bob') ON CONFLICT (name) DO NOTHING

Azure function inserting but not updating cosmosDB

☆樱花仙子☆ 提交于 2019-12-25 02:12:31
问题 I have an azure function taking in messages from an Azure service bus queue and sending documents to cosmosDB. I'm using Azure functions 1.x: public static class Function1 { [FunctionName("Function1")] public static void Run([ServiceBusTrigger("ServiceBusQueue", AccessRights.Manage, Connection = "ServiceBusQueueConnection")]BrokeredMessage current, [DocumentDB( databaseName: "DBname", collectionName: "Colname", ConnectionStringSetting = "CosmosDBConnection")]out dynamic document, TraceWriter

Race Condition between SELECT and INSERT for multiple columns

允我心安 提交于 2019-12-24 08:59:08
问题 Note: This is a question which is a follow up of this solution. You need to read the link to get context for this question. Also, this is for postgres v9.4 If we want to return multiple columns now instead of just 1 column, how can we achieve it? Let's take a table t: create table t(tag_id int, tag text unique); Now this is what I want: whenever I call a method f_tag_id, I want it to return all the columns for the unique row if it exists in the table t else insert it and return all the