Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incremental models sql_where value changes between delete and insert statements #138

Closed
jthandy opened this issue Sep 10, 2016 · 0 comments
Labels
bug Something isn't working
Milestone

Comments

@jthandy
Copy link
Member

jthandy commented Sep 10, 2016

I have a model that specifies the following for an incremental model:

  sql_where = "rev_rec_date >= (select max(rev_rec_date) from {{this}})",
  unique_key = "account_id || '.' || date_month"

In theory, this is exactly how this is supposed to work. In practice, this fails. The delete statement runs, deletes the records, and then when the insert statement runs, it picks up a different value for max(rev_rec_date), which causes it to get a bunch more records.

It's deleting 40 records and then inserting 143 records, but it should actually be deleting 40 and inserting 40 (because they are daily records and I've already run it for today). The extra 103 records are actually duplicated records from the previous day, because they match the new value for max(rev_rec_date).

I can demonstrate this live if needed.

I think the only solution for this is to create a temporary table with the values and then run both the delete and the insert off of that temporary table. We've discussed this before, but I think this bug moves that from a nice enhancement to something we need ASAP to create correct behavior.

@jthandy jthandy added the bug Something isn't working label Sep 10, 2016
@drewbanin drewbanin added this to the 0.5.0 Release milestone Sep 20, 2016
drewbanin pushed a commit that referenced this issue Sep 20, 2016
this should speed up query times and also provide a more
correct implementation.

See: #138
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants