MCPcopy Create free account
hub / github.com/cloudquery/cloudquery / deleteInsert

Method deleteInsert

plugins/destination/duckdb/client/write.go:224–245  ·  view source on GitHub ↗
(ctx context.Context, tmpTableName string, table *schema.Table)

Source from the content-addressed store, hash-verified

222}
223
224func (c *Client) deleteInsert(ctx context.Context, tmpTableName string, table *schema.Table) error {
225 if err := c.deleteByPK(ctx, tmpTableName, table); err != nil {
226 return err
227 }
228
229 sb := new(strings.Builder)
230 sb.WriteString("INSERT INTO ")
231 sb.WriteString(table.Name)
232 sb.WriteString("(" + strings.Join(sanitized(table.Columns.Names()), ", ") + ")")
233 sb.WriteString(" SELECT ")
234 sb.WriteString(strings.Join(sanitized(table.Columns.Names()), ", "))
235 sb.WriteString(" FROM ")
236 sb.WriteString(tmpTableName)
237 sb.WriteString(" ON CONFLICT DO NOTHING")
238 query := sb.String()
239
240 // per https://duckdb.org/docs/sql/indexes#over-eager-unique-constraint-checking we might need to retry
241 _, err := backoff.Retry(ctx, func() (any, error) {
242 return nil, c.exec(ctx, query)
243 }, backoff.WithBackOff(backoff.NewConstantBackOff(50*time.Millisecond)), backoff.WithMaxTries(3))
244 return err
245}

Callers 1

WriteTableBatchMethod · 0.95

Calls 4

deleteByPKMethod · 0.95
execMethod · 0.95
sanitizedFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected