Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work with redshift #29

Merged
merged 2 commits into from
Jun 28, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions drivers/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package postgres
import (
"database/sql"
"fmt"
"github.com/k1LoW/tbls/schema"
"regexp"
"strings"

"github.com/k1LoW/tbls/schema"
)

var reFK = regexp.MustCompile(`FOREIGN KEY \((.+)\) REFERENCES ([^\s]+)\s?\((.+)\)`)
Expand All @@ -18,10 +19,13 @@ func (p *Postgres) Analyze(db *sql.DB, s *schema.Schema) error {

// tables
tableRows, err := db.Query(`
SELECT CONCAT(table_schema, '."', table_name, '"')::regclass::oid AS oid, table_name, table_type
SELECT DISTINCT cls.oid AS oid, cls.relname AS table_name, tbl.table_type AS table_type
FROM pg_catalog.pg_class cls
INNER JOIN pg_namespace ns ON cls.relnamespace = ns.oid
INNER JOIN (SELECT table_name, table_type
FROM information_schema.tables
WHERE table_schema != 'pg_catalog' AND table_schema != 'information_schema'
AND table_catalog = $1
AND table_catalog = $1) tbl ON cls.relname = tbl.table_name
ORDER BY oid`, s.Name)
defer tableRows.Close()
if err != nil {
Expand Down