lib/pgslice/table.rb in pgslice-0.4.6 vs lib/pgslice/table.rb in pgslice-0.4.7

- old
+ new

@@ -21,19 +21,21 @@ # http://www.dbforums.com/showthread.php?1667561-How-to-list-sequences-and-the-columns-by-SQL def sequences query = <<-SQL SELECT - a.attname as related_column, - s.relname as sequence_name + a.attname AS related_column, + n.nspname AS sequence_schema, + s.relname AS sequence_name FROM pg_class s - JOIN pg_depend d ON d.objid = s.oid - JOIN pg_class t ON d.objid = s.oid AND d.refobjid = t.oid - JOIN pg_attribute a ON (d.refobjid, d.refobjsubid) = (a.attrelid, a.attnum) - JOIN pg_namespace n ON n.oid = s.relnamespace + INNER JOIN pg_depend d ON d.objid = s.oid + INNER JOIN pg_class t ON d.objid = s.oid AND d.refobjid = t.oid + INNER JOIN pg_attribute a ON (d.refobjid, d.refobjsubid) = (a.attrelid, a.attnum) + INNER JOIN pg_namespace n ON n.oid = s.relnamespace + INNER JOIN pg_namespace nt ON nt.oid = t.relnamespace WHERE s.relkind = 'S' - AND n.nspname = $1 + AND nt.nspname = $1 AND t.relname = $2 ORDER BY s.relname ASC SQL execute(query, [schema, name]) end @@ -107,9 +109,10 @@ conditions << where if where query << " WHERE #{conditions.join(" AND ")}" if conditions.any? (execute(query)[0]["min"] || 1).to_i end + # ensure this returns partitions in the correct order def partitions query = <<-SQL SELECT nmsp_child.nspname AS schema, child.relname AS name