Skip to content

Commit 491941a

Browse files
authored
fix(tests): Postgresql: Read only columns defined in the schema (#6371)
The PostgreSQL read test should only read and return the columns defined in our schema. This will allow https://github.com/cloudquery/plugin-sdk/pull/574/files to pass.
1 parent cab6e1e commit 491941a

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

  • plugins/destination/postgresql/client

plugins/destination/postgresql/client/read.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,23 @@ package client
33
import (
44
"context"
55
"fmt"
6+
"strings"
67

78
"github.com/cloudquery/plugin-sdk/schema"
89
"github.com/jackc/pgx/v5"
910
)
1011

1112
const (
12-
readSQL = "SELECT * FROM %s WHERE _cq_source_name = $1 order by _cq_sync_time asc"
13+
readSQL = "SELECT %s FROM %s WHERE _cq_source_name = $1 order by _cq_sync_time asc"
1314
)
1415

1516
func (c *Client) Read(ctx context.Context, table *schema.Table, sourceName string, res chan<- []any) error {
16-
sql := fmt.Sprintf(readSQL, pgx.Identifier{table.Name}.Sanitize())
17+
colNames := make([]string, 0, len(table.Columns))
18+
for _, col := range table.Columns {
19+
colNames = append(colNames, pgx.Identifier{col.Name}.Sanitize())
20+
}
21+
cols := strings.Join(colNames, ",")
22+
sql := fmt.Sprintf(readSQL, cols, pgx.Identifier{table.Name}.Sanitize())
1723
rows, err := c.conn.Query(ctx, sql, sourceName)
1824
if err != nil {
1925
return err

0 commit comments

Comments
 (0)