From b6ffc57f8060e0f46f85ea3737599e40eab90d24 Mon Sep 17 00:00:00 2001 From: TossPig Date: Tue, 25 Aug 2015 22:37:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9GetColumns=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 防止数据库中,存在多个schema同表名,不同的字段属性的污染 --- postgres_dialect.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/postgres_dialect.go b/postgres_dialect.go index 67ceecd0..972a214f 100644 --- a/postgres_dialect.go +++ b/postgres_dialect.go @@ -913,7 +913,8 @@ func (db *postgres) IsColumnExist(tableName, colName string) (bool, error) { } func (db *postgres) GetColumns(tableName string) ([]string, map[string]*core.Column, error) { - args := []interface{}{tableName} + pgSchema := "public" + args := []interface{}{tableName,pgSchema} s := `SELECT column_name, column_default, is_nullable, data_type, character_maximum_length, numeric_precision, numeric_precision_radix , CASE WHEN p.contype = 'p' THEN true ELSE false END AS primarykey, CASE WHEN p.contype = 'u' THEN true ELSE false END AS uniquekey @@ -924,7 +925,7 @@ FROM pg_attribute f LEFT JOIN pg_constraint p ON p.conrelid = c.oid AND f.attnum = ANY (p.conkey) LEFT JOIN pg_class AS g ON p.confrelid = g.oid LEFT JOIN INFORMATION_SCHEMA.COLUMNS s ON s.column_name=f.attname AND c.relname=s.table_name -WHERE c.relkind = 'r'::char AND c.relname = $1 AND f.attnum > 0 ORDER BY f.attnum;` +WHERE c.relkind = 'r'::char AND c.relname = $1 AND s.table_schema = $2 AND f.attnum > 0 ORDER BY f.attnum;` rows, err := db.DB().Query(s, args...) if db.Logger != nil {