On Wed, Mar 16, 2016 at 3:23 PM, Piotr Dobrogost <
[email protected]> wrote:

> On Wednesday, March 16, 2016 at 3:51:16 PM UTC+1, Simon King wrote:
>>
>> On Wed, Mar 16, 2016 at 1:43 PM, Piotr Dobrogost <
>> [email protected]> wrote:
>>
>>> Hi!
>>>
>>> When executing below code
>>>
>>> DBSession.query(TextValue).\
>>>         filter(Node.id.in_(ids)).\
>>>         update({TextValue.value: appstruct['text_value']},
>>>                      synchronize_session=False)
>>>
>>> I get this error:
>>> OperationalError: (sqlite3.OperationalError) near "FROM": syntax error
>>> [SQL: u'UPDATE text_values SET value=? FROM nodes WHERE nodes.id IN (?,
>>> ?, ?, ?)'] [parameters: (u'zzz', u'1685', u'175', u'1688', u'180')]
>>>
>>>
>>>
>
>> I'm not sure if sqlite supports multi-table updates. Do you know what
>> sort of SQL you are expecting to generate here?
>>
>
> I would expect "normal" UPDATE with WHERE clause. I'm not sure where does
> FROM come from here as the new value is given explicitly and not to be read
> from existing rows.
>
>
>> (Note that your query appears at least to be missing a join condition
>> between the TextValue and Node classes)
>>
>
> TextValue is a subclass of Content which is a subclass of Node.
> Content declares this:
> @classproperty
> def __mapper_args__(cls):
>     return dict(polymorphic_identity=camel_case_to_name(cls.__name__))
>
> so TextValue and Node should be implicitly joined according to rules for
> joined table polymorphism in SA.
>

Hmm, ok. In that case, does it work if you use "TextValue.id.in_(ids)"
rather than Node? I can't tell from your description if the "id" and
"value" columns are both present on the TextValue table, or if you actually
need to join to the Node class.

It does seem like a bug that SA is generating this SQL.

Simon

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to