Let's Suppose I have two tables - Source and Target. I am trying to Load Target table from Source, and the record should be inserted only if it is not present in the target table, else it should be updated. All the columns should be considered for the comparisons. Is there any options available in Informix other than Merge statement.
How to perform Update else Insert Operation win INFORMIX without MERGE Statement
310 views Asked by Vignesh Kiswanth At
1
There are 1 answers
Related Questions in SQL
- SQL schema for a fill-in-the-blank exercise
- Hibernate: JOIN inheritance question - why the need for two left joins
- What's supposed to be the problem in this query?
- Compare fields in two tables
- How to change woocomerce or full wordpress currency with value from USD to AUD
- Dynamic query creation with Array like implementation
- SQL query to get student enrolled in this month in a course - Moodle
- SQL LAG() function returning 0 for every row despite available previous rows
- Convert C# DateTime.Ticks to Bigquery DateTime Format
- Use row values from another table to select them as columns and establish relations between them (pivot table)
- SQL: Generate combination table based on source and destination column from same table
- how to use system's environnement variables in sql script
- PHP fetchAll on JOIN
- Multitable joining in Sql
- How to display name starting from 'z' by using BETWEEN cmd only?
Related Questions in INFORMIX
- Informix Golang client package
- How to resolve this error when using OpenQuery in SQL Server to extract data from an Informix database
- Trigger/Stored Procedure causing sql error 127 Informix 12.10.FC10
- Update a huge number of rows without lock entire table in Informix
- Informix ODBC Driver][Informix]A character to numeric conversion process
- Update rows in an Informix database by incrementing serial numbers
- Informix - get DB Server Name / Alias for connected Session
- How can get full name from INFO TABLES at Informix DB
- Is there a way to get the sql statement about the creation of the row type?
- How to connect to informix DB using data direct informix driver and python on Linux
- IBM VS.NET SE Integration & Extensions package did not load correctly
- IBM Informix Error "-556 Cannot create, drop or modify an object that is external to the current Database"
- Find opaque types in the Informix database
- Informix: SQL does not accept double quote to surround a string
- Update a table in informix (an entire field)
Related Questions in INSERT-UPDATE
- Update scenario is not working properly when using CASEs or IF statement ON DUPLICATE KEY UPDATE section in MySQL
- Update many documents by pushing an object to an array field when id field matches the id field in the object
- Creating a datafactory pipeline for updating an insering records
- Delta Tables...do we need partitions for concurrent write/update?
- How to save each instance from a patch request in Djanog
- PHP Update API php://input returning unexpected response
- Value of one field in one entity has been changed after hibernate call saveOrUpdate
- Update Access Database Table using Excel VBA
- how to write a update statement SQL Oracle developer to get data from tables and input it into their own columns
- How to rightly configure an Azure data factory data flow with a delta file as sink?
- If I have multiple entries in a cloumn in mysql that need to be changed
- R6 array member, copy on update
- How to up files with Bitrix24 api
- How to insert new key-value pairs to an existing elastic document using python?
- Stored Procedure: Update or Insert data between two databases on the same mysql server
Related Questions in MERGE-STATEMENT
- merge statement query
- How to create a data-traced table using merge statement in Bigquery
- Oracle OJDBC MERGE Statement and Generated Keys
- Resolve the error: The multi-part identifier could not be bound?
- SQL Server - Using MERGE statement between 2 Databases on 2 different servers
- SQL Server Merge Update With Partial Sources
- Merge statement in SNOWFLAKE database on primary key error
- How do I update the two different tables using if and else condition in Oracle SQL server?
- I'm trying to create a dynamic merge query inside a stored procedure where target is a history table and source is a temporary table - SQL Server
- How can I use insert with select from other table in a merge statement?
- How to perform Update else Insert Operation win INFORMIX without MERGE Statement
- Hash_md5() in not working while merging in Exasol
- BigQuery MERGE statement with NESTED+REPEATED fields
- Facing an issue in MERGE SQL query
- BigQuery Equivalent of Merge Statement
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Popular Tags
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
As you now know, the MERGE statement was not present in Informix 10.00 (or any version prior to 11.50.xC6).
There isn't a simple way around it.
In outline, the closest approximation is:
Identify the primary key columns in the source and target tables — I'm going to assume they're single-column keys with names
src_primary_keyandtgt_primary_key. Life is more complex if they're multi-column keys, but not insuperably so.Nominally, you would insert the missing records using:
However, you probably run foul of restrictions on selecting from the table you're also inserting into, so you end up doing:
Since you want the updates to replace the existing data, you then arrange to create a list of present keys:
All of this has to be done inside a transaction to be safe, of course — probably at REPEATABLE READ isolation for maximum safety.
There are probably other ways to do this, but this loosely simulates the steps that the MERGE statement would go through. You might need to deal with 'Present Keys' before dealing with 'Missing Keys' (so execute step 3 after executing step 4). You might also think about whether to simply delete all the rows from Target that match a row in Source, and then simply insert the contents of Source into Target: