from sqlalchemy import Column
from sqlalchemy import Integer
from sqlalchemy import update
from sqlalchemy.dialects import postgresql
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class A(Base):
__tablename__ = 'a'
id = Column(Integer, primary_key=True)
data = Column(JSONB)
stmt = update(A).values({A.data: A.data + {"key": "value"}}).where(A.id == 5)
print(stmt.compile(dialect=postgresql.dialect()))
On Fri, Oct 16, 2020, at 4:00 AM, Massimiliano della Rovere wrote:
> Greetings,
> how should I write the .values() section of a CORE update() statement to
> render the following
> postgres syntax?
>
> The data column is a JSON(B) and contains a dict object.
>
> UPDATE settings
> SET data = data || '{"key": "value"}'
> WHERE key = 'my_param';
>
> Thanks,
> Massimiliano
>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
> description.
> ---
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sqlalchemy/CADKhPGSpo79VpastaH-PJMPQ-WDYFLEkMeCXVhTm0f9U4zJQLw%40mail.gmail.com
>
> <https://groups.google.com/d/msgid/sqlalchemy/CADKhPGSpo79VpastaH-PJMPQ-WDYFLEkMeCXVhTm0f9U4zJQLw%40mail.gmail.com?utm_medium=email&utm_source=footer>.
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sqlalchemy/645d7868-2798-4ec6-9d72-a489e4a0e8e9%40www.fastmail.com.