Skip to content

Comments

Support postgresql partitioning by making INSERT RETURNING optional#5698

Merged
tenderlove merged 6 commits intorails:masterfrom
dougcole:support_postgresql_partitioning
Apr 27, 2012
Merged

Support postgresql partitioning by making INSERT RETURNING optional#5698
tenderlove merged 6 commits intorails:masterfrom
dougcole:support_postgresql_partitioning

Conversation

@dougcole
Copy link
Contributor

@dougcole dougcole commented Apr 1, 2012

Currently the Postgresql adapters use of INSERT RETURNING for insert statements makes using trigger based partitioning of tables impossible (See http://www.postgresql.org/docs/9.1/static/ddl-partitioning.html for more info). This patch adds a per connection option to disable INSERT RETURNING and use a simpler INSERT; SELECT currval() which works with trigger based inserts. Fixes #4955

@tenderlove
Copy link
Member

I'm not sure it's a good idea that you can toggle this on and off at any time. It means that we can't make expectations about the connection behavior (for example someone upstream could just toggle the flag).

Would you be opposed to supporting something where the database.yml specified the flag? For example:

---
  production:
    adapter: postgresql
    insert_returning: false

@dougcole
Copy link
Contributor Author

dougcole commented Apr 3, 2012

That makes sense, I'll make the change and let you know when it's done.

@tenderlove
Copy link
Member

Awesome! Thank you for the work, I really appreciate it.

@dougcole
Copy link
Contributor Author

dougcole commented Apr 8, 2012

@tenderlove OK, updated. Let me know what you think, I like the change a lot, thanks for the suggestion and all the help!

@dougcole
Copy link
Contributor Author

dougcole commented Apr 9, 2012

Feel free to give more feedback, I'm happy to refactor more. I know I'm adding a lot of complexity to the postgresql adapter for a rarely used feature, I want to make sure it's not too much of pain to maintain.

@dougcole
Copy link
Contributor Author

bump. Sorry to nag, just wanted to make sure you saw the new revision - anything else I can do to help with this?

tenderlove added a commit that referenced this pull request Apr 27, 2012
Support postgresql partitioning by making INSERT RETURNING optional
@tenderlove tenderlove merged commit 8de4d71 into rails:master Apr 27, 2012
@tecnobrat
Copy link

I am not sure the normal routine as far as rails releases go. I see this has been merged into master. Will it ever be merged into 3.2? Or will it only make it into the next major version?

@carlosantoniodasilva
Copy link
Member

@tecnobrat it's probably a hard work to backport, and since it seems more like a new feature than a bug fix, it's unlikely to be done by any commiter. In any case, if you want to try out a pull request backporting it, by cherry-picking these commits and doing any required changes, then there's a chance to get it into 3.2. Cheers!

@rafaelfranca
Copy link
Member

I don't think this should be backported since it is adding feature and changes the public API. If we backport this some database adapters can break.

@CarlosEspejo
Copy link

Ive been stuck on this partitioning problem all week until I found this discussion. How come there's no mention of insert_returning in any of the Rails guides?

casperisfine pushed a commit to Shopify/rails that referenced this pull request Jul 31, 2024
It was introduced in rails#49290
likely to do the same as PostgresqlAdapter, but it's not used
anywhere and there not really any reason to have that option.

Postgres has it because INSERT RETURNING can't be used in some
corner cases, see: rails#5698
joelhawksley pushed a commit to joelhawksley/rails that referenced this pull request Aug 8, 2024
It was introduced in rails#49290
likely to do the same as PostgresqlAdapter, but it's not used
anywhere and there not really any reason to have that option.

Postgres has it because INSERT RETURNING can't be used in some
corner cases, see: rails#5698
joelhawksley pushed a commit to joelhawksley/rails that referenced this pull request Aug 8, 2024
It was introduced in rails#49290
likely to do the same as PostgresqlAdapter, but it's not used
anywhere and there not really any reason to have that option.

Postgres has it because INSERT RETURNING can't be used in some
corner cases, see: rails#5698
DanielaVelasquez pushed a commit to DanielaVelasquez/rails that referenced this pull request Oct 3, 2024
It was introduced in rails#49290
likely to do the same as PostgresqlAdapter, but it's not used
anywhere and there not really any reason to have that option.

Postgres has it because INSERT RETURNING can't be used in some
corner cases, see: rails#5698
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ActiveRecord 3.1 removes support for posgresql trigger based partitioning

6 participants