INSERT), which according to wikipeda, has the form:
MERGE INTO tablename USING table_reference ON (condition) WHEN MATCHED THEN UPDATE SET column1 = value1 [, column2 = value2 ...] WHEN NOT MATCHED THEN INSERT (column1 [, column2 ...]) VALUES (value1 [, value2 ...]);
If the ON field(s) in the Source matches the ON field(s) in the Target, then UPDATE
If the ON field(s) in the Source does not match the ON field(s) in the Target, then INSERT
I was wondering if there is a
SELECT version of it (without side effects) that returns the would-be result of the updated target table without actually changing the target table?
Using PostgreSQL 9.5’s
INSERT INTO ... ON CONFLICT [ conflict_target ] conflict_action statement (pointed out in wikipedia) as an example. Given a target table
distributors and an update table
distributors_upd as follows:
DROP TABLE IF EXISTS distributors; DROP TABLE IF EXISTS distributors_upd; CREATE TABLE distributors (did INTEGER PRIMARY KEY, dname VARCHAR); INSERT INTO distributors VALUES (5, 'Gizmo Transglobal'), (6, 'Associated Computing, Inc'); CREATE TABLE distributors_upd (did INTEGER PRIMARY KEY, dname VARCHAR); INSERT INTO distributors_upd VALUES (5, 'Gizmo Transglobal*');
Is there an effective query to get the result of a
UPSERT without actually changing the target table
I tried to mimic the effect with:
WITH distributors_updated AS ( INSERT INTO distributors (did, dname) (TABLE distributors_upd) ON CONFLICT (did) DO UPDATE SET dname = EXCLUDED.dname RETURNING * ) --SELECT * FROM distributors; SELECT * FROM distributors_updated;
Neither one of the last two lines gives the would-be result:
did | dname -----+--------------------------- 6 | Associated Computing, Inc 5 | Gizmo Transglobal*
... SELECT * FROM distributors shows the original table (by design).
-----+--------------------------- 5 | Gizmo Transglobal 6 | Associated Computing, Inc (2 rows)
... SELECT * FROM distributors_updated shows the change rows only.
-----+-------------------- 5 | Gizmo Transglobal* (1 row)
The content of
distributors is changed either way. Is there an effective query returning the “merged”/”unioned” without actually changing the target
✓ Extra quality
ExtraProxies brings the best proxy quality for you with our private and reliable proxies
✓ Extra anonymity
Top level of anonymity and 100% safe proxies – this is what you get with every proxy package
✓ Extra speed
1,ooo mb/s proxy servers speed – we are way better than others – just enjoy our proxies!
USA proxy location
We offer premium quality USA private proxies – the most essential proxies you can ever want from USA
Our proxies have TOP level of anonymity + Elite quality, so you are always safe and secure with your proxies
Use your proxies as much as you want – we have no limits for data transfer and bandwidth, unlimited usage!
Superb fast proxy servers with 1,000 mb/s speed – sit back and enjoy your lightning fast private proxies!
99,9% servers uptime
Alive and working proxies all the time – we are taking care of our servers so you can use them without any problems
No usage restrictions
You have freedom to use your proxies with every software, browser or website you want without restrictions
Perfect for SEO
We are 100% friendly with all SEO tasks as well as internet marketing – feel the power with our proxies
Buy more proxies and get better price – we offer various proxy packages with great deals and discounts
We are working 24/7 to bring the best proxy experience for you – we are glad to help and assist you!