sql-merge

T-SQL MERGE Performance in typical publishing context

廉价感情. 提交于 2019-12-01 01:34:04
I have situation where a "publisher" application essentially keeps a view model up to date by querying a VERY complex view and then merging the results into a denormalized view model table, using separate insert, update, and delete operations. Now that we have upgraded to SQL 2008 I figured it would be a great time to update these with the SQL MERGE statement. However after writing the query, the subtree cost of the MERGE statement is 1214.54! With the old way, the sum of the Insert/Update/Delete was only 0.104!! I can't figure out how a more straightforward way of describing the same exact

Oracle MERGE statement in H2 database

自闭症网瘾萝莉.ら 提交于 2019-12-01 00:20:05
问题 We started to use the H2 in memory database for automated testing. We use Oracle for our production & dev environments. So the idea is to duplicate the table structure in H2 test-database as it is in our Oracle dev-database. The Oracle SQL statements include MERGE statements and use alias for table names and USING in the query. How can I modify this query dynamically to be compatible with H2 in a way that it does not alter the existing query in the dev environment? Example of the Oracle SQL,

UPDATE or MERGE of very big tables in SQL Server

こ雲淡風輕ζ 提交于 2019-11-30 03:47:16
问题 I need to perform a daily update of a very large (300M records) and broad TABLE1 . The the source data for the updates is located in another table UTABLE that is 10%-25% the rows of TABLE1 but is narrow. Both tables have record_id as a primary key. Presently, I am recreating TABLE1 using the following approach: <!-- language: sql --> 1) SELECT (required columns) INTO TMP_TABLE1 FROM TABLE1 T join UTABLE U on T.record_id=U.record_id 2) DROP TABLE TABLE1 3) sp_rename 'TMP_TABLE1', 'TABLE1'

SQL Server MERGE + Joining other tables

余生颓废 提交于 2019-11-29 18:05:53
问题 I am using the MERGE statement within a database project to populate reference data from a static value set, such as the following below: MERGE INTO dbo.[User] AS TARGET USING (VALUES ('me@somewhere.com', 'My Name')) AS SOURCE(UserName, FullName) ON SOURCE.UserName = TARGET.UserName WHEN NOT MATCHED BY TARGET THEN INSERT (UserId, UserName, FullName) VALUES (NEWID(), UserName, FullName); The problem comes in when I want to populate the secondary table based of content in other tables. For

Teradata MERGE yielding no results when executed through SQLAlchemy

北城余情 提交于 2019-11-28 01:41:00
I'm attempting to use python with sqlalchemy to download some data, create a temporary staging table on a Teradata Server, then MERGEing that table into another table which I've created to permanently store this data. I'm using sql = slqalchemy.text(merge) and td_engine.execute(sql) where merge is a string similar to the below: MERGE INTO perm_table as p USING temp_table as t ON p.Id = t.Id WHEN MATCHED THEN UPDATE SET col1 = t.col1, col2 = t.col2, ... col50 = t.col50 WHEN NOT MATCHED THEN INSERT (col1, col2, ... col50) VALUES (t.col1, t.col2, ... t.col50) The script runs all the way to the

Teradata MERGE yielding no results when executed through SQLAlchemy

谁都会走 提交于 2019-11-26 23:33:37
问题 I'm attempting to use python with sqlalchemy to download some data, create a temporary staging table on a Teradata Server, then MERGEing that table into another table which I've created to permanently store this data. I'm using sql = slqalchemy.text(merge) and td_engine.execute(sql) where merge is a string similar to the below: MERGE INTO perm_table as p USING temp_table as t ON p.Id = t.Id WHEN MATCHED THEN UPDATE SET col1 = t.col1, col2 = t.col2, ... col50 = t.col50 WHEN NOT MATCHED THEN

Insert, on duplicate update in PostgreSQL?

廉价感情. 提交于 2019-11-26 03:12:54
问题 Several months ago I learned from an answer on Stack Overflow how to perform multiple updates at once in MySQL using the following syntax: INSERT INTO table (id, field, field2) VALUES (1, A, X), (2, B, Y), (3, C, Z) ON DUPLICATE KEY UPDATE field=VALUES(Col1), field2=VALUES(Col2); I\'ve now switched over to PostgreSQL and apparently this is not correct. It\'s referring to all the correct tables so I assume it\'s a matter of different keywords being used but I\'m not sure where in the

ORA-30926: unable to get a stable set of rows in the source tables

徘徊边缘 提交于 2019-11-26 00:44:02
问题 I am getting ORA-30926: unable to get a stable set of rows in the source tables in the following query: MERGE INTO table_1 a USING (SELECT a.ROWID row_id, \'Y\' FROM table_1 a ,table_2 b ,table_3 c WHERE a.mbr = c.mbr AND b.head = c.head AND b.type_of_action <> \'6\') src ON ( a.ROWID = src.row_id ) WHEN MATCHED THEN UPDATE SET in_correct = \'Y\'; I\'ve ran table_1 it has data and also I\'ve ran the inside query ( src ) which also has data. Why would this error come and how can it be resolved

How to UPSERT (MERGE, INSERT … ON DUPLICATE UPDATE) in PostgreSQL?

送分小仙女□ 提交于 2019-11-25 21:41:50
问题 A very frequently asked question here is how to do an upsert, which is what MySQL calls INSERT ... ON DUPLICATE UPDATE and the standard supports as part of the MERGE operation. Given that PostgreSQL doesn\'t support it directly (before pg 9.5), how do you do this? Consider the following: CREATE TABLE testtable ( id integer PRIMARY KEY, somedata text NOT NULL ); INSERT INTO testtable (id, somedata) VALUES (1, \'fred\'), (2, \'bob\'); Now imagine that you want to \"upsert\" the tuples (2, \'Joe