Skip to content

Commit

Permalink
[postgres] Remove unused error return from castColumn (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-artie authored Mar 18, 2024
1 parent cca8a08 commit 9b870d9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
16 changes: 6 additions & 10 deletions lib/postgres/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,18 @@ func (s scanAdapter) ParsePrimaryKeyValue(columnName string, value string) (any,
}

// castColumn will take a colName and return the escaped version of what we should be using to call Postgres.
func castColumn(col schema.Column) (string, error) {
func castColumn(col schema.Column) string {
colName := pgx.Identifier{col.Name}.Sanitize()
switch col.Type {
case schema.TimeWithTimeZone:
// If we don't convert `time with time zone` to UTC we end up with strings like `10:23:54-02`
// And pgtype.Time doesn't parse the offset propertly.
// See https://github.com/jackc/pgx/issues/1940
return fmt.Sprintf(`%s AT TIME ZONE 'UTC' AS "%s"`, colName, col.Name), nil
return fmt.Sprintf(`%s AT TIME ZONE 'UTC' AS "%s"`, colName, col.Name)
case schema.Array:
return fmt.Sprintf(`ARRAY_TO_JSON(%s)::TEXT as "%s"`, colName, col.Name), nil
return fmt.Sprintf(`ARRAY_TO_JSON(%s)::TEXT as "%s"`, colName, col.Name)
default:
return colName, nil
return colName
}
}

Expand All @@ -162,12 +162,8 @@ func queryPlaceholders(offset, count int) []string {

func (s scanAdapter) BuildQuery(primaryKeys []primary_key.Key, isFirstBatch bool, batchSize uint) (string, []any, error) {
castedColumns := make([]string, len(s.columns))
for idx, col := range s.columns {
var err error
castedColumns[idx], err = castColumn(col)
if err != nil {
return "", nil, err
}
for i, col := range s.columns {
castedColumns[i] = castColumn(col)
}

startingValues := make([]any, len(primaryKeys))
Expand Down
5 changes: 2 additions & 3 deletions lib/postgres/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ func TestCastColumn(t *testing.T) {
}

for _, testCase := range testCases {
actualEscCol, err := castColumn(schema.Column{Name: "foo", Type: testCase.dataType})
assert.NoError(t, err, testCase.name)
assert.Equal(t, testCase.expected, actualEscCol, testCase.name)
actual := castColumn(schema.Column{Name: "foo", Type: testCase.dataType})
assert.Equal(t, testCase.expected, actual, testCase.name)
}
}

Expand Down

0 comments on commit 9b870d9

Please sign in to comment.