As mentioned on the subject, I'm getting an error when inserting/updating rows. I want the records to insert if new and update if existing. The keys are a combination of 2 fields (code and date).
Help, please.
Output tool while using db connection has a similar option "Update: inset if new" (insert if new and update if existing) you can try that out.
Hope this helps : )
@atcodedog05, I think that's the one I'm using already. 🙂
I did a workaround by adding another field to the database table. I set the value at current datetime so that the value always gets updated. Seems that the error occurs when all fields are exactly similar. I wonder if there's another way to do without having to add a new field. For future reference.
This is an interesting problem. I've never had any problems with Insert:Update if new. If the record is found based on the primary key fields, the other fields in the record are updated. If not a new row is inserted.
Is this a case where the primary key in the database includes all the fields in the table?
Dan
Hi, @danilang.
"Is this a case where the primary key in the database includes all the fields in the table?"
No, Sir. I think the problem occurs when the values being update are the same as the values being updated with. In short, the row has the exactly the same values for all columns.
As mentioned, I had to append a datetime field to ensure that a certain value is always moving.
We have many workflows that do exactly this. They work fine when passed records where all the fields are identical to the existing record. You might want to reach out to Alteryx directly about this, support@alteryx.com. Make sure to include details about the connection method you're using, ODBC, OLEdb, etc as well what database you're using and the driver details.
Dan
We use Oracle tables primarily, and I usually encounter this when:
If you are the owner of the destination table, you might try this:
For example, I had to use the code below in the Post Create SQL Statement box when I first created my output Oracle table (after which I set it to Update; Insert if New):
ALTER TABLE "EXCHANGE_RATE_SUMMARY"
MODIFY "PERIOD" DATE NOT NULL
MODIFY "CURRENCY" VARCHAR2 (20) NOT NULL;
ALTER TABLE "EXCHANGE_RATE_SUMMARY"
ADD CONSTRAINT "ExchangeRateSummary" PRIMARY KEY ("PERIOD", "CURRENCY");
User | Count |
---|---|
17 | |
15 | |
15 | |
8 | |
5 |