Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix: pg query with comment (#9595)

zll6003e3c4059103f
diff --git a/backend/plugin/db/pg/pg.go b/backend/plugin/db/pg/pg.go
index 529079562e..42d6a5882b 100644
--- a/backend/plugin/db/pg/pg.go
+++ b/backend/plugin/db/pg/pg.go
@@ -477,7 +477,10 @@ func (driver *Driver) QueryConn(ctx context.Context, conn *sql.Conn, statement s
}
func getStatementWithResultLimit(stmt string, limit int) string {
- return fmt.Sprintf("WITH result AS (%s) SELECT * FROM result LIMIT %d;", stmt, limit)
+ // To handle cases where there are comments in the query.
+ // eg. select * from t1 -- this is comment;
+ // Add two new line symbol here.
+ return fmt.Sprintf("WITH result AS (\n%s\n) SELECT * FROM result LIMIT %d;", stmt, limit)
}
func (*Driver) querySingleSQL(ctx context.Context, conn *sql.Conn, singleSQL base.SingleSQL, queryContext *db.QueryContext) (*v1pb.QueryResult, error) {