Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demo for update-only table #876

Open
bobvawter opened this issue May 20, 2024 · 0 comments
Open

Demo for update-only table #876

bobvawter opened this issue May 20, 2024 · 0 comments

Comments

@bobvawter
Copy link
Contributor

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 */ -}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant