upsert

Sequelize upsert() never updates and only inserts

故事扮演 提交于 2020-07-09 03:04:54
问题 So I'm trying to use the model.upsert() of sequelize and all i receive is inserts , no matter what i change in the query. I have a Transaction model that has some fields, with the default generated id. reading the sequelize's upsert documentation i noticed this: An update will be executed if a row which matches the supplied values on either the primary key or a unique key is found. Note that the unique index must be defined in your sequelize model and not just in the table. So i was guessing

Sequelize upsert() never updates and only inserts

依然范特西╮ 提交于 2020-07-09 03:01:24
问题 So I'm trying to use the model.upsert() of sequelize and all i receive is inserts , no matter what i change in the query. I have a Transaction model that has some fields, with the default generated id. reading the sequelize's upsert documentation i noticed this: An update will be executed if a row which matches the supplied values on either the primary key or a unique key is found. Note that the unique index must be defined in your sequelize model and not just in the table. So i was guessing

How to upsert pandas DataFrame to PostgreSQL table?

百般思念 提交于 2020-06-28 05:44:26
问题 I've scraped some data from web sources and stored it all in a pandas DataFrame. Now, in order harness the powerful db tools afforded by SQLAlchemy, I want to convert said DataFrame into a Table() object and eventually upsert all data into a PostgreSQL table. If this is practical, what is a workable method of going about accomplishing this task? 回答1: If you are using PostgreSQL 9.5 or later you can perform the UPSERT using a temporary table and an INSERT ... ON CONFLICT statement: with engine

MongoError: cannot infer query fields to set, path 'users' is matched twice

旧城冷巷雨未停 提交于 2020-05-26 11:43:51
问题 I am using mongoose. I want to create a document chat with an array users (including userId1 , userId2 ), if I do not find it: This is how I do: ChatModel.findOneAndUpdate( { users: { $all: [userId1, userId2] }}, { $setOnInsert: { users: [userId1, userId2] }}, { upsert: true }) .exec() .catch(err => console.log(err)); But I got the error: MongoError: cannot infer query fields to set, path 'users' is matched twice This is Chat Schema: { users: [{ type: Schema.Types.ObjectId, ref: 'User' }],

MongoError: cannot infer query fields to set, path 'users' is matched twice

守給你的承諾、 提交于 2020-05-26 11:43:35
问题 I am using mongoose. I want to create a document chat with an array users (including userId1 , userId2 ), if I do not find it: This is how I do: ChatModel.findOneAndUpdate( { users: { $all: [userId1, userId2] }}, { $setOnInsert: { users: [userId1, userId2] }}, { upsert: true }) .exec() .catch(err => console.log(err)); But I got the error: MongoError: cannot infer query fields to set, path 'users' is matched twice This is Chat Schema: { users: [{ type: Schema.Types.ObjectId, ref: 'User' }],

Postgres on conflict do update on composite primary keys

拥有回忆 提交于 2020-05-26 10:51:25
问题 I have a table where a user answers to a question. The rules are that the user can answer to many questions or many users can answer one question BUT a user can answer to a particular question only once. If the user answers to the question again, it should simply replace the old one. Generally the on conflict do update works when we are dealing with unique columns. In this scenario the columns person_id and question_id cannot be unique. However the combination of the two is always unique. How

How to disambiguate a plpgsql variable name in a ON CONFLICT clause?

送分小仙女□ 提交于 2020-03-21 20:04:13
问题 Given this table: create table test ( name text primary key ); I need to write a plpgsql function with a variable name that collides with the primary key name, which I must use in a on conflict clause: create or replace function func( name text -- this variable name... ) returns void language plpgsql as $$ begin insert into test (name) values (name) on conflict (name) do update -- ...conflicts with this line set name = func.name; end; $$; This compiles, but then throws an ambiguous column

Need to convert Oracle “merge into” query to PostgreSQL

限于喜欢 提交于 2020-01-25 06:53:45
问题 I'm trying to convert the following Oracle query to PostgreSQL: MERGE into feepay.TRPT_W2_REPORTS TRPT1 USING( WITH RWS AS (SELECT PROG.BINCLIENT, TRPT.PUT_DIRECTORY FROM feepay.program2 PROG INNER JOIN feepay.TRPT_W2_PROGRAMS TRPT ON (PROG.BINCLIENT = TRPT.BINCLIENT OR PROG.ISSUER_ID = TRPT.ISSUER_ID)) SELECT TCI.CUSTOMERNAME AS ACCOUNT, TC.CUSTOMER_ID AS urn, TC.LAST_NAME, TC.FIRST_NAME, TC.DOB, TCA.ADDRESS FROM feepay.TAU_CARDNUMBERS TCN INNER JOIN feepay.TAU_CUSTOMER_CARDNUMBER TCCN ON