From 5f3517eb4d0eb8b07d4964f9a9f8f27c200e8144 Mon Sep 17 00:00:00 2001 From: Robin Tang Date: Tue, 15 Oct 2024 20:11:56 -0700 Subject: [PATCH] Tweak flow. --- clients/redshift/staging.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/clients/redshift/staging.go b/clients/redshift/staging.go index 70acb1288..f1084dbf7 100644 --- a/clients/redshift/staging.go +++ b/clients/redshift/staging.go @@ -26,11 +26,7 @@ func (s *Store) PrepareTemporaryTable(ctx context.Context, tableData *optimizati } for colName, newValue := range colToNewLengthMap { - // Generate queries and then update the [tableConfig] with the new string precision. - if _, err = s.Exec(s.dialect().BuildIncreaseStringPrecisionQuery(parentTableID, colName, newValue)); err != nil { - return fmt.Errorf("failed to increase string precision for table %q: %w", parentTableID.FullyQualifiedName(), err) - } - + // Try to upsert columns first. If this fails, we won't need to update the destination table. err = tableConfig.Columns().UpsertColumn(colName, columns.UpsertColumnArg{ StringPrecision: typing.ToPtr(newValue), }) @@ -38,6 +34,10 @@ func (s *Store) PrepareTemporaryTable(ctx context.Context, tableData *optimizati if err != nil { return fmt.Errorf("failed to update table config with new string precision: %w", err) } + + if _, err = s.Exec(s.dialect().BuildIncreaseStringPrecisionQuery(parentTableID, colName, newValue)); err != nil { + return fmt.Errorf("failed to increase string precision for table %q: %w", parentTableID.FullyQualifiedName(), err) + } } if createTempTable {