You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is an upsert template hack to make a table update-only. This could also be accomplished though a custom apply function, which would make a nice demo of either diff options or by using a SQL call to ping the table row. We could also choose to support an insert- or update-only mode for some table as a baked-in behavior.
{{- /*gotype: github.com/cockroachdb/replicator/internal/target/apply.templates*/ -}}
{{- /*
This is a demonstration template to only perform updates over existing rows.
*/ -}}
WITH raw_data( {{- template "names" .Columns -}} ) AS (
VALUES{{- nl -}}
{{- template "exprs" . -}}
)
UPDATE {{ .TableName }} t SET {{- nl -}}
{{- range $idx, $col := .Data -}}
{{- if $idx -}},{{- end -}}
{{- $col.Name -}}=d.{{- $col.Name -}}
{{- end -}} {{- nl -}}
FROM raw_data d
WHERE {{- nl -}}
{{- range $idx, $col := .PK -}}
{{- if $idx }} AND {{ end -}}
t.{{- $col.Name -}}=d.{{- $col.Name -}}
{{- end -}}
{{- /* Trim whitespace */ -}}
The text was updated successfully, but these errors were encountered:
This is an upsert template hack to make a table update-only. This could also be accomplished though a custom
apply
function, which would make a nice demo of eitherdiff
options or by using a SQL call to ping the table row. We could also choose to support an insert- or update-only mode for some table as a baked-in behavior.The text was updated successfully, but these errors were encountered: