Explorar o código

fix: goctl pg gen will extract all fields when the same table name exists in different schemas (#3496) (#3517)

POABOB hai 1 ano
pai
achega
33f6d7ebb8
Modificáronse 1 ficheiros con 6 adicións e 4 borrados
  1. 6 4
      tools/goctl/model/sql/model/postgresqlmodel.go

+ 6 - 4
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)