Add support for PosgreSQL ONLY feature #448

Closed
wants to merge 3 commits into
from

Conversation

Projects
None yet
2 participants
Contributor

funny-falcon commented Feb 29, 2012

Add support for selecting from ONLY #{table} when dealing with PostgreSQL

Owner

jeremyevans commented Feb 29, 2012

Unfortunately, I don't think this is a good fit for inclusion in Sequel. This is a PostgreSQL specific feature, and a fairly niche one at that (only databases using table inheritance), so it shouldn't be loaded by default. I recommend you package the code as a Sequel extension. Note that your extension could be as easy as:

# or a module included in Symbol, SQL::Identifier, etc.
class Symbol
  def pg_only
     "ONLY ?".lit(self)
  end
end

As your use case is PostgreSQL-only, using literal SQL should be acceptable.

Contributor

funny-falcon commented Feb 29, 2012

Well, `"ONLY ?".lit(self)" does not handle joins :(

I rewrote it as sequel/extensions/pg_from_only. Is it now better?
I placed tests into spec/adapters/postgres_spec.rb cause they depends on PostgreSQL connection, but may be it is not best place.

Owner

jeremyevans commented Feb 29, 2012

It fails on joins only because Sequel can't determine the table alias to use from a literal string. That's trivial to work around:

class Symbol
  def pg_only
     "ONLY ?".lit(self).as(self)
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment