Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

postgres, quote table names when fetching the primary key (#5920) #7850

Merged
merged 1 commit into from

2 participants

@senny
Owner

quote the table name when fetching the primary key information for a postgres table.

@senny
Owner

@steveklabnik I quoted the table name to fetch the primary key information.

@tenderlove I did not search for other occurrences where the table name appears unquoted. Do you think this patch is enough to get AR working with capital letter tables?

@rafaelfranca
Owner

I think is enough.

Could you change the commit message to:

PostgreSQL, quote table names when fetching the primary key. Closes #5920
@senny
Owner

@rafaelfranca the commit message is updated and the branch is rebased.

@rafaelfranca rafaelfranca merged commit 9b496d3 into from
@rafaelfranca
Owner

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 5, 2012
  1. @senny
This page is out of date. Refresh to see the latest.
View
5 activerecord/CHANGELOG.md
@@ -1,5 +1,10 @@
## Rails 4.0.0 (unreleased) ##
+* The postgres adapter now supports tables with capital letters.
+ Fix #5920
+
+ *Yves Senn*
+
* `CollectionAssociation#count` returns `0` without querying if the
parent record is not persisted.
View
2  activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
@@ -314,7 +314,7 @@ def primary_key(table)
INNER JOIN pg_depend dep ON attr.attrelid = dep.refobjid AND attr.attnum = dep.refobjsubid
INNER JOIN pg_constraint cons ON attr.attrelid = cons.conrelid AND attr.attnum = cons.conkey[1]
WHERE cons.contype = 'p'
- AND dep.refobjid = '#{table}'::regclass
+ AND dep.refobjid = '#{quote_table_name(table)}'::regclass
end_sql
row && row.first
View
4 activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb
@@ -14,6 +14,10 @@ def test_primary_key
assert_equal 'id', @connection.primary_key('ex')
end
+ def test_primary_key_works_tables_containing_capital_letters
+ assert_equal 'id', @connection.primary_key('CamelCase')
+ end
+
def test_non_standard_primary_key
@connection.exec_query('drop table if exists ex')
@connection.exec_query('create table ex(data character varying(255) primary key)')
Something went wrong with that request. Please try again.