I’m unable to modify Data row using the following SQLAlchemy statement:
stmt = (
update(models.Data)
.values(
custom_columns=(
func.coalesce(
func.jsonb_set(
func.jsonb_set(
cast(models.Data.custom_columns, JSONB),
'{archived}',
cast(
models.Data.custom_columns['archived'],
JSONB
).op('||')(
func.jsonb_build_object(
old_key,
cast(
models.Data.custom_columns['fields'][old_key],
JSONB
)
)
)
),
'{fields}',
cast(
cast(models.Data.custom_columns, JSONB)['fields'],
JSONB
).op('-')(old_key)
),
cast(models.Data.custom_columns, JSONB)
)
),
updated_at=func.now()
)
.where(
cast(models.Data.custom_columns, JSONB)['fields'].has_key(old_key)
)
.where(models.Data.project_id == project_id)
)
Can someone help?
Tried to delete key, value from “fields” inside “custom_columns” and create “archived” inside custom_columns and add deleted key, value in “archived”
New contributor
Muhammad Khalid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.