upsert

UPSERT Postgres 9.5

不问归期 提交于 2019-12-11 04:35:42
问题 I am using Postgres 9.5 on CentOS 6. I have the following table (DDL). CREATE TABLE core_table.user_list( user_id SMALLSERIAL DEFAULT nextval('core_table.user_list_user_id_seq'::regclass) NOT NULL, user_name VARCHAR(50) NOT NULL, full_name VARCHAR(255), role_id INTEGER DEFAULT 1, is_accessible INTEGER DEFAULT 1, remarks VARCHAR(255), password VARCHAR(50), customer_schema VARCHAR(50), core_schema VARCHAR(50), CONSTRAINT user_list_pkey PRIMARY KEY(user_id, user_name), CONSTRAINT user_list_user

How to get affected row count of table inside wCTE-based upsert in postgresql?

寵の児 提交于 2019-12-11 03:17:34
问题 i need your help, I have a query with n times loop operation of insert and update. I decided to use 'UPSERT', since it doesn’t require loop operation. ex: WITH upsert AS (UPDATE employee_table SET rollno=input_rollno, name=input_name RETURNING *) INSERT INTO employee_table (rollno, name) SELECT 'input_rollno',input_name from employee_table WHERE NOT EXISTS (SELECT * FROM upsert); The query is working fine and now the problem is, i want the affected row counts of individual insert and update..

Mysql UPDATE ON DUPLICATE KEY only inserting

我的未来我决定 提交于 2019-12-11 03:14:09
问题 I am trying to run a query so that it will insert or update on duplicate. I am using a unique index for the duplicate but I cannot seem to get it to work. It still adds new records. Hoping some fresh eyes can point out my issue. Thanks. This is my schema CREATE TABLE IF NOT EXISTS `pricing_puchasing` ( `custno` varchar(6) DEFAULT NULL COMMENT 'customer code', `recipe` varchar(15) DEFAULT NULL, `item` varchar(120) NOT NULL COMMENT 'Item Code from dProduce', `unit_weight` double(12,4) DEFAULT

How can I perform an UPSERT using Azure DocumentDB?

被刻印的时光 ゝ 提交于 2019-12-10 18:46:03
问题 Azure DocumentDB does not support UPSERT. Is there a reasonable work around to achieve the same functionality? Is using a stored procedure which checks if the document exists to determine whether and insert or update should be performed an effective strategy? What if I need to perform thousands of these in bulk? Vote for the feature here: http://feedback.azure.com/forums/263030-documentdb/suggestions/7075256-provide-for-upsert Update - Here is my attempt at a bulk upsert stored procedure.

UPSERT in SQLite

守給你的承諾、 提交于 2019-12-10 17:42:47
问题 I don't want to use REPLACE INTO because it's basically a DELETE and INSERT and it's complicated to use the data from the old columns. INSERT OR IGNORE is a bit of a hack because all errors are ignored, so this is not an option. I've read a blog article which uses the following: UPDATE Table1 SET (...) WHERE Column1='SomeValue' IF @@ROWCOUNT=0 INSERT INTO Table1 VALUES (...) I like this approach really much, but I don't know how I can implement this IF-clause with the @@ROWCOUNT in SQLite,

Upsert in Postgres using node.js

妖精的绣舞 提交于 2019-12-10 15:48:02
问题 I'm trying to do an insert or update in a postgres database using node.js with pg extension (version 0.5.4). So far I have this code: (...) client.query({ text: "update users set is_active = 0, ip = $1 where id=$2", values: [ip,id] }, function(u_err, u_result){ debug(socket_id,"update query result: ",u_result); debug(socket_id,"update query error: ",u_err); date_now = new Date(); var month = date_now.getMonth() + 1; if(!u_err){ client.query({ text: 'insert into users (id,first_name,last_name

Python peewee save() doesn't work as expected

ⅰ亾dé卋堺 提交于 2019-12-10 15:16:42
问题 I'm inserting/updating objects into a MySQL database using the peewee ORM for Python. I have a model like this: class Person(Model): person_id = CharField(primary_key=True) name = CharField() I create the objects/rows with a loop, and each time through the loop have a dictionary like: pd = {"name":"Alice","person_id":"A123456"} Then I try creating an object and saving it. po = Person() for key,value in pd.items(): setattr(po,key,value) po.save() This takes a while to execute, and runs without

Postgresql upsert with JDBC parameter markers

我只是一个虾纸丫 提交于 2019-12-10 10:08:00
问题 I've got an INSERT statement that works today when called from JDBC using parameters markers: INSERT INTO errorqueue as eq (jobname, sourceid, item) VALUES(?,?,?) In my Java code, I bind the parameters: Connection connection=null; PreparedStatement stmt=null; try { connection = getConnection(); stmt = connection.prepareStatement(sqlInsert); stmt.setString(1, this.jobName); stmt.setString(2, errorItem.getId()); stmt.setString(3, item.getBody()); stmt.executeUpdate(); } catch () { ... } I'm

Upsert in Rails ActiveRecord

强颜欢笑 提交于 2019-12-09 08:02:20
问题 Does ActiveRecord have a built-in upsert functionality? I know I could write it myself but I obviously don't want to if such a thing already exists. 回答1: Model.find_or_initialize likely does what you want. You can chain it with save or update_attributes if that makes sense. More info in the Rails Guides. 回答2: I just ran across this library: https://github.com/seamusabshere/upsert I haven't tested it yet, but it looks promising 回答3: There is an awesome new feature in rails 6: they added upsert

How to implement a conditional Upsert stored procedure?

安稳与你 提交于 2019-12-09 04:51:25
问题 I'm trying to implement your basic UPSERT functionality, but with a twist: sometimes I don't want to actually update an existing row. Essentially I'm trying to synchronize some data between different repositories, and an Upsert function seemed like the way to go. So based largely on Sam Saffron's answer to this question, as well as some other research and reading, I came up with this stored procedure: (note: I'm using MS SQL Server 2005, so the MERGE statement isn't an option) CREATE