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

Added no_returning option for Postgres to insert without RETURNING clause #276

Merged
merged 1 commit into from
Jun 22, 2016

Conversation

makaroni4
Copy link
Contributor

Motivation for this PR: enable import without RETURNING clause (right now for every INSERT statement RETURNING clause is applied). This will allow to use Postgres rules for insertion, for example the rule to simply ignore all duplications inside INSERT statement.

Right now if we have smth like this in DB (Postgres younger than 9.5)

CREATE OR REPLACE RULE events_duplicate_ignore AS ON insert TO events
  WHERE EXISTS(
    SELECT 1
    FROM events
    WHERE (mask)=(NEW.mask)
  )
  DO INSTEAD NOTHING;

and try to insert duplicate we'll have an error ActiveRecord::StatementInvalid: PG::FeatureNotSupported: ERROR: cannot perform INSERT RETURNING on relation "events" HINT: You need an unconditional ON INSERT DO INSTEAD rule with a RETURNING clause.

@makaroni4
Copy link
Contributor Author

Hi Jordan!

Thanks for the quick response! I think there is even more general case –
import should perform like 1 insert. So RETURNING enables you to work with
new entries right after you inserted them. But for import I don't think
it's usually the case – the ultimate goal is to just have this records in
db (like any analytics data). What do you think?

Btw I used my branch in our production setup for importing data – works
super smooth, the rule in postgres just ignores duplicated data on insert.

Best,
Anatoli

On 17 May 2016 at 00:23, Jordan Owens notifications@github.com wrote:

@makaroni4 https://github.com/makaroni4 I believe the RETURNING clause
was added to make :recursive import possible. Instead of a new option
:no_returning, I'm wondering if you could just check and see if :recursive
is enabled? If not skip appending that clause.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#276 (comment)

@jkowens
Copy link
Collaborator

jkowens commented May 17, 2016

After more thought I decided your explicit option is the better choice, so I give it a 👍

@makaroni4 makaroni4 closed this May 17, 2016
@makaroni4 makaroni4 reopened this May 17, 2016
@makaroni4
Copy link
Contributor Author

@jkowens any idea about failing AR 5 tests? Looks like latest AR RC has some issue with mysql, there is same error in other PR.

@jkowens
Copy link
Collaborator

jkowens commented May 19, 2016

@makaroni4 yeah it turns out the seamless_database_pool gem is not currently compatible with ActiveRecord 5.0.0.rc1. I sent up a PR to fix, so hopefully there will be an updated release in the near future.

See bdurand/seamless_database_pool#25

cc: @zdennis

@makaroni4 makaroni4 closed this Jun 4, 2016
@makaroni4 makaroni4 reopened this Jun 4, 2016
@zdennis
Copy link
Owner

zdennis commented Jun 12, 2016

@makaroni4, seamless_database_pool is happy now in master thanks to @jkowens. Would you mind rebasing?

@makaroni4
Copy link
Contributor Author

@zdennis done, squashed commits into 1 🚀

@jkowens jkowens mentioned this pull request Jun 20, 2016
5 tasks
@zdennis
Copy link
Owner

zdennis commented Jun 22, 2016

Thank you @makaroni4 !

@zdennis zdennis merged commit db02550 into zdennis:master Jun 22, 2016
@zdennis zdennis added the 0.14.0 label Jun 22, 2016
@zdennis
Copy link
Owner

zdennis commented Jun 22, 2016

This is going out in the 0.14.0 release.

@zdennis
Copy link
Owner

zdennis commented Jun 22, 2016

Bummer, this breaks TravisCI, but I think that is a JDBCDriver error. I'm not going to hold up the release due to the error, will investigate later and will possibly skip if this is a known limitation with that driver.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants