If SQLAlchemy didn't support the second calling style, you would still
be able to make this work using the Python "**" operator:
updatevalues = {custom_column: value}
query = AIRPORT.update().values(**updatevalues)
When calling a function, passing "**somedictionary" is equivalent to
passing each of the dictionary elements as keyword arguments to the
function.
>>> def f(a, b, c):
... print("a =", a)
... print("b =", b)
... print("c =", c)
...
>>> f(a=1, b=2, c=3)
a = 1
b = 2
c = 3
>>> args = {'a': 1, 'b': 2, 'c': 3}
>>> f(**args)
a = 1
b = 2
c = 3
Simon
On Fri, Jul 12, 2019 at 10:28 AM Mirek Morek <[email protected]> wrote:
>
> It works!
>
> Thank you very much Simon, I really appreciate that. You saved me a lot of
> nerves. I would buy you a beer if I could.
>
> So, in general we can say that only second calling style works in my example.
>
> Regards.
>
> W dniu czwartek, 11 lipca 2019 16:35:25 UTC+2 użytkownik Simon King napisał:
>>
>> Here are the docs for the Update.values() method:
>>
>> https://docs.sqlalchemy.org/en/13/core/dml.html#sqlalchemy.sql.expression.Update.values
>>
>> Note that it supports two main calling styles, either keyword arguments:
>>
>> .values(name_column='cat')
>>
>> ...or passing a dictionary:
>>
>> .values({'name_column': 'cat'})
>>
>> Since you want to choose the column dynamically, you can use the
>> dictionary style:
>>
>> updatevalues = {custom_column: value}
>> query = AIRPORT.update().values(updatevalues)
>>
>> Hope that helps,
>>
>> Simon
>>
>> On Thu, Jul 11, 2019 at 3:00 PM Mirek Morek <[email protected]> wrote:
>> >
>> > Hello everyone,
>> > I have a following question:
>> >
>> > I use sqlalchemy within my python method as follows:
>> >
>> >
>> > I want to be able to replace 'custom_column' with parameter passed in the
>> > method. The same way as it works fine for airport_sys_id, project_sys_id
>> > and value.
>> >
>> > For example I want to pass in my method (1, 2, name_column, cat) and
>> > receive as follows:
>> >
>> > query = AIRPORT.update(). \
>> > where(AIRPORT.c.airport_sys_id == 1). \
>> > where(AIRPORT.c.project_sys_id == 2). \
>> > values(name_column=cat)
>> >
>> > I searched all I could but with no success. I would be extremely thankful
>> > for your support. Regards.
>> >
>> >
>> > --
>> > 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 post to this group, send email to [email protected].
>> > Visit this group at https://groups.google.com/group/sqlalchemy.
>> > To view this discussion on the web visit
>> > https://groups.google.com/d/msgid/sqlalchemy/67448673-060d-449c-9dd9-19d5049c0c72%40googlegroups.com.
>> > For more options, visit https://groups.google.com/d/optout.
>
> --
> 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 post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/sqlalchemy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sqlalchemy/11786218-4161-4d41-b4e1-6faa7a31611b%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
--
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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sqlalchemy/CAFHwexcdGOyrHVav1paXPFs1V4HbsEiJSuC1pSezd1Us4R0UOw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.