From 0b8faeaaf3cf3d27bf81372f9a1b01ae81037288 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Fri, 22 Dec 2023 14:16:07 -0500 Subject: [PATCH] Replcae CAST with TRY_CAST --- flow/connectors/snowflake/snowflake.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flow/connectors/snowflake/snowflake.go b/flow/connectors/snowflake/snowflake.go index e61830db88..391733a1df 100644 --- a/flow/connectors/snowflake/snowflake.go +++ b/flow/connectors/snowflake/snowflake.go @@ -837,11 +837,11 @@ func (c *SnowflakeConnector) generateAndExecuteMergeStatement( "AS %s,", toVariantColumnName, columnName, targetColumnName)) case qvalue.QValueKindGeography: flattenedCastsSQLArray = append(flattenedCastsSQLArray, - fmt.Sprintf("TO_GEOGRAPHY(CAST(%s:\"%s\" AS STRING),true) AS %s,", + fmt.Sprintf("TO_GEOGRAPHY(TRY_CAST(%s:\"%s\" AS STRING),true) AS %s,", toVariantColumnName, columnName, targetColumnName)) case qvalue.QValueKindGeometry: flattenedCastsSQLArray = append(flattenedCastsSQLArray, - fmt.Sprintf("TO_GEOMETRY(CAST(%s:\"%s\" AS STRING),true) AS %s,", + fmt.Sprintf("TO_GEOMETRY(TRY_CAST(%s:\"%s\" AS STRING),true) AS %s,", toVariantColumnName, columnName, targetColumnName)) // TODO: https://github.com/PeerDB-io/peerdb/issues/189 - handle time types and interval types // case model.ColumnTypeTime: @@ -849,7 +849,7 @@ func (c *SnowflakeConnector) generateAndExecuteMergeStatement( // "Microseconds*1000) "+ // "AS %s,", toVariantColumnName, columnName, columnName)) default: - flattenedCastsSQLArray = append(flattenedCastsSQLArray, fmt.Sprintf("CAST(%s:\"%s\" AS %s) AS %s,", + flattenedCastsSQLArray = append(flattenedCastsSQLArray, fmt.Sprintf("TRY_CAST(%s:\"%s\" AS %s) AS %s,", toVariantColumnName, columnName, sfType, targetColumnName)) } }