From 33f6d7ebb8197201c47ea6a81e8bf33d6042e5f7 Mon Sep 17 00:00:00 2001 From: POABOB <38785340+POABOB@users.noreply.github.com> Date: Mon, 4 Sep 2023 20:48:26 +0800 Subject: [PATCH] fix: goctl pg gen will extract all fields when the same table name exists in different schemas (#3496) (#3517) --- tools/goctl/model/sql/model/postgresqlmodel.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tools/goctl/model/sql/model/postgresqlmodel.go b/tools/goctl/model/sql/model/postgresqlmodel.go index 4d056cc0..8c095700 100644 --- a/tools/goctl/model/sql/model/postgresqlmodel.go +++ b/tools/goctl/model/sql/model/postgresqlmodel.go @@ -72,7 +72,8 @@ from ( t.typname AS type, a.atttypmod AS lengthvar, a.attnotnull AS not_null, - b.description AS comment + b.description AS comment, + (c.relnamespace::regnamespace)::varchar AS schema_name FROM pg_class c, pg_attribute a LEFT OUTER JOIN pg_description b ON a.attrelid = b.objoid AND a.attnum = b.objsubid, @@ -81,10 +82,11 @@ from ( and a.attnum > 0 and a.attrelid = c.oid and a.atttypid = t.oid - GROUP BY a.attnum, c.relname, a.attname, t.typname, a.atttypmod, a.attnotnull, b.description + GROUP BY a.attnum, c.relname, a.attname, t.typname, a.atttypmod, a.attnotnull, b.description, c.relnamespace::regnamespace ORDER BY a.attnum) AS t - left join information_schema.columns AS c on t.relname = c.table_name - and t.field = c.column_name and c.table_schema = $2` + left join information_schema.columns AS c on t.relname = c.table_name and t.schema_name = c.table_schema + and t.field = c.column_name + where c.table_schema = $2` var reply []*PostgreColumn err := m.conn.QueryRowsPartial(&reply, querySql, table, schema)