MCPcopy Index your code
hub / github.com/sqldef/sqldef / getPrimaryKeyInfosForTables

Method getPrimaryKeyInfosForTables

database/postgres/database.go:1354–1390  ·  view source on GitHub ↗
(tableNames []string)

Source from the content-addressed store, hash-verified

1352}
1353
1354func (d *PostgresDatabase) getPrimaryKeyInfosForTables(tableNames []string) (map[string]primaryKeyInfo, error) {
1355 var selectCols string
1356 if d.supportsConperiod() {
1357 selectCols = "con.conname, con.conperiod"
1358 } else {
1359 selectCols = "con.conname, false"
1360 }
1361 query := fmt.Sprintf(`
1362 SELECT nsp.nspname || '.' || cls.relname AS qualified_table_name, %s
1363 FROM pg_constraint con
1364 JOIN pg_class cls ON cls.oid = con.conrelid
1365 JOIN pg_namespace nsp ON nsp.oid = cls.relnamespace
1366 WHERE nsp.nspname || '.' || cls.relname = ANY($1::text[])
1367 AND con.contype = 'p'
1368 `, selectCols)
1369
1370 rows, err := d.db.Query(query, pq.Array(tableNames))
1371 if err != nil {
1372 return nil, err
1373 }
1374 defer rows.Close()
1375
1376 result := make(map[string]primaryKeyInfo, len(tableNames))
1377 for rows.Next() {
1378 var tableName, keyName string
1379 var period bool
1380 err = rows.Scan(&tableName, &keyName, &period)
1381 if err != nil {
1382 return nil, err
1383 }
1384 result[tableName] = primaryKeyInfo{
1385 name: NewIdentWithQuoteDetected(keyName),
1386 period: period,
1387 }
1388 }
1389 return result, nil
1390}
1391
1392func (d *PostgresDatabase) getIndexDefsForTables(tableNames []string) (map[string][]string, error) {
1393 // Exclude indexes that are implicitly created for primary keys or unique constraints or exclusion constraints.

Callers 1

Calls 6

supportsConperiodMethod · 0.95
QueryMethod · 0.80
NextMethod · 0.80
ScanMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected