(tableNames []string)
| 1645 | } |
| 1646 | |
| 1647 | func (d *PostgresDatabase) getCheckConstraintsForTables(tableNames []string) (map[string][]CheckConstraint, error) { |
| 1648 | const query = `SELECT nsp.nspname || '.' || cls.relname AS qualified_table_name, con.conname, pg_get_constraintdef(con.oid, true) |
| 1649 | FROM pg_constraint con |
| 1650 | JOIN pg_namespace nsp ON nsp.oid = con.connamespace |
| 1651 | JOIN pg_class cls ON cls.oid = con.conrelid |
| 1652 | WHERE con.contype = 'c' |
| 1653 | AND nsp.nspname || '.' || cls.relname = ANY($1::text[]) |
| 1654 | AND array_length(con.conkey, 1) > 1` |
| 1655 | |
| 1656 | rows, err := d.db.Query(query, pq.Array(tableNames)) |
| 1657 | if err != nil { |
| 1658 | return nil, err |
| 1659 | } |
| 1660 | defer rows.Close() |
| 1661 | |
| 1662 | result := make(map[string][]CheckConstraint, len(tableNames)) |
| 1663 | for rows.Next() { |
| 1664 | var tableName, constraintName, constraintDef string |
| 1665 | err = rows.Scan(&tableName, &constraintName, &constraintDef) |
| 1666 | if err != nil { |
| 1667 | return nil, err |
| 1668 | } |
| 1669 | // Normalize type casts for generic parser compatibility |
| 1670 | // PostgreSQL returns "::time without time zone" but the generic parser expects "::time" |
| 1671 | constraintDef = normalizePostgresTypeCasts(constraintDef) |
| 1672 | result[tableName] = append(result[tableName], CheckConstraint{ |
| 1673 | Name: NewIdentWithQuoteDetected(constraintName), |
| 1674 | Definition: constraintDef, |
| 1675 | }) |
| 1676 | } |
| 1677 | return result, nil |
| 1678 | } |
| 1679 | |
| 1680 | func (d *PostgresDatabase) getUniqueConstraintsForTables(tableNames []string) (map[string]map[string]string, error) { |
| 1681 | const query = `SELECT nsp.nspname || '.' || cls.relname AS qualified_table_name, nsp.nspname, cls.relname, con.conname, pg_get_constraintdef(con.oid) |
no test coverage detected