MySQL INSERT ... ON DUPLICATE KEY UPDATE - need vertica analogue
In MySQL if you trying to insert a record, and it violates unique/primary constraint, it can update existing record.
https://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html
Does vertica have anything similar?
Thanks.
0
Comments
No you can't do that in Vertica. Why? That functionality is the result of lazy development.
So, what is 'not lazy' option?
I need to save large amount of data to db - fast.
In Mysql I can group updates to batches, and perform batch in single transatction. And I don't need to check if records in batch violates constraints.
Any ideas how can I achieve this in vertica would be helpful.
Thanks.
Primary keys can be enabled or disabled. By default they are disabled. You can change that behavior via the EnableNewPrimaryKeysByDefault database parameter.
Note you can always UPDATE a PK even when a PK is enabled.
Example:
Maybe the MERGE command can do what you want?
Here I UPDATE the matching rows:
And here I INSERT a new row as there are no matching records:
Yes, That's what I was looking for!
Many-many thanks.
Cool!
By the way, I your user name
I get the following error if i do the same -
ERROR [42601] ERROR: Subquery in MERGE is not supported;
@Deepak_Nailwal - Can you post your SQL statement?
This works:
See:
https://www.vertica.com/docs/9.2.x/HTML/Content/Authoring/AdministratorsGuide/Tables/MergeTables/MergeSourceData.htm
I'm using Vertica 8.x. Probably it was introduced in Vertica 9.2.
As a work around, create a database view using your subquery...
Example: