1. INSERT .. ON CONFLICT is an implementation UPSERT technique
2. MERGE is something meant to be different from UPSERT but has UPSERT feature?
81–90 of 114 posts
1. INSERT .. ON CONFLICT is an implementation UPSERT technique
2. MERGE is something meant to be different from UPSERT but has UPSERT feature?
Very thankful to all the hard working Postgres devs. PostgreSQL was really good when I first started using it, and just keeps getting better. Glad to see the general community finally getting on the PostgreSQL bandwagon.
Now let's see if I can get more people to use internal PostgreSQL functions instead of constantly writing statements directly in their code.
I know it doesn't matter to some developers out there, but for me, the only thing left is the ability to add a column after another one. Even if it's only logical order, it's easier for me to read a table structure when fields are ordered nicely.
ORA-01779: cannot modify a column which maps to a non key-preserved table
ORA-30926: unable to get a stable set of rows in the source tables
Slightly OT, why do we see these errors with Oracle's MERGE statements? ORA-01779: cannot modify a column which maps to a non key-preserved table ORA-30926: unable to get a stable set of rows in the source tables
CREATE OR REPLACE RULE "replace_row" AS
ON INSERT TO my_table
WHERE EXISTS(SELECT 1 FROM my_table WHERE id=NEW.id)
DO INSTEAD
(UPDATE my_table SET
col1=NEW.col1,
col2=NEW.col2,
col3=NEW.col3,
WHERE id=NEW.id);Slightly OT, why do we see these errors with Oracle's MERGE statements? ORA-01779: cannot modify a column which maps to a non key-preserved table ORA-30926: unable to get a stable set of rows in the source tables
Asking a support question on a feature announcement post for a completely unrelated product is EXTREMELY off topic.
Does anyone know when this is expected to be released?
Earlier quoted context omitted.
It's fairly trivial to do with a savepoint, but it's definitely not performant, and requires some pretty stupid client-side error-handling. It will also cause your Postgres logs to be littered with benign but misleading error messages (possibly these could be silenced, I never bothered to find out). So, yes, this is great news.
Minor nit: it's performant and doesn't pollute logs to implement this on the server side. I've written macros to make gen'ing upsert functions easy, given a certain table pattern. But this definitely cleans that situation up as well as makes it accessible to more casual developers.
I've been looking forward to this for ages! The solution we use at the moment for upsert is a create or replace rule on the table but it isn't great as you need to remember to update the rule whenever you change the table schema... CREATE OR REPLACE RULE "replace_row" AS ON INSERT TO my_table WHERE EXISTS(SELECT 1 FROM my_table WHERE id=NEW.id) DO INSTEAD (UPDATE my_table SET col1=NEW.col1, col2=NEW.col2, col3=NEW.co…
For one, the WHERE EXISTS() will not see concurrent insertions by transactions that are still in progress, which means you'll still get constraint violation errors.
For another, rules generally have very surprising behaviour. E.g. with this RULE you'll get into trouble if "id" isn't passed in as a explicit value, but uses a non-deterministic DEFAULT or directly passed in expression. Every reference to NEW.id will not be replaced by the result of that expression, but rather with the expression itself. For the common serial id column (aka autoincrement) you'll have a separate nextval() call in each reference. Which can make this explode in pretty damn confusing ways.