Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #5906 (reopened defect)

Opened 2 years ago

Last modified 11 months ago

[PATCH] PostgreSQL adapter does not see tables in schema search path

Reported by: netghost@gmail.com Assigned to: bitsweat
Priority: normal Milestone:
Component: ActiveRecord Version: 1.2.1
Severity: normal Keywords: postgresql search_path schema tables
Cc:

Description

The postgresql adapter will fail to see tables in any schema except the first one listed due to the way it parses the schema search path.

For instance, using a connection such as: development:

adapter: postgresql database: ... username: ... password: schema_search_path: public,partitions

Will only show tables in the public schema. This occurs because the schema list includes spaces when queried ie: "public, partitions" and when converted into a query it will look like: "'public',' partitions'" and hence 'partitions' will be missed.

The patch is pretty trivial:

175c175
<         schemas = schema_search_path.split(/,/).map { |p| quote(p) }.join(',')
---
>         schemas = schema_search_path.split(/\s*,\s*/).map { |p| quote(p) }.join(',')

Hope that helps,

.adam sanderson

Oh this is showing up in postgresql 8.1, I don't know if this behavior existed prior to 8.1.

Attachments

postgresql_adapter.diff (180 bytes) - added by Adam Sanderson / netghost on 08/25/06 02:06:05.
Diff file for the patch listed above
postgresql_adapter.rb.patch (0.6 kB) - added by baudelairien on 07/03/07 01:55:06.
same patch, but updated for rails 1-2-1
schema_test_postgresql.rb.patch (0.6 kB) - added by baudelairien on 07/03/07 01:56:29.
unit test for patch to bug #5906 (dup #3125)

Change History

08/25/06 02:06:05 changed by Adam Sanderson / netghost

  • attachment postgresql_adapter.diff added.

Diff file for the patch listed above

08/25/06 03:17:44 changed by bitsweat

  • owner changed from David to bitsweat.
  • milestone changed from 1.x to 1.2.

Please include a unit test demonstrating the correct behavior. Thanks!

09/04/06 00:03:26 changed by bitsweat

  • status changed from new to closed.
  • resolution set to untested.

07/03/07 01:55:06 changed by baudelairien

  • attachment postgresql_adapter.rb.patch added.

same patch, but updated for rails 1-2-1

07/03/07 01:56:29 changed by baudelairien

  • attachment schema_test_postgresql.rb.patch added.

unit test for patch to bug #5906 (dup #3125)

07/03/07 01:58:52 changed by baudelairien

  • status changed from closed to reopened.
  • resolution deleted.

Updated patch and added unit test. Reopening.

(This ticket is a duplicate of #3125, also closed for lack of patch/test.)

07/03/07 01:59:16 changed by baudelairien

  • keywords changed from postgresql schema tables to postgresql search_path schema tables.
  • version changed from 0.14.4. to 1.2.1.
  • milestone deleted.

07/03/07 02:19:03 changed by baudelairien

This bug is aggrevated by the fact that Postgresql (using postmaster 8.1.4 under OS X Intel 10.4.9, with ruby-postgres gem 0.7.1.2005.12.21) injects spaces into the search_path whether or not they were present in the assignment. This seems to happen independently of the ruby driver. In PSQL:

db_dev=> SET search_path = demo,public; SET db_dev=> SHOW search_path;

search_path


demo, public

(1 row)

PostgreSQLAdapter#schema_search_path uses "SHOW search_path".