func.cast() is not correct. Use the cast() function which handles this special
syntax:
from sqlalchemy import cast, Integer
from sqlalchemy.sql import column
from sqlalchemy.dialects import oracle
print cast(column('x'), Integer).compile(dialect=oracle.dialect())
CAST(x AS INTEGER)
On Apr 18, 2012, at 10:30 AM, jo wrote:
> I'm using oracle. The error exists even without REGEXP_LIKE:
>
> session.query(sa.func.max(sa.func.cast(sa.func.substr(Azienda.c.codice_aziendale,2),
> sa.Integer))).scalar()
>
> NotSupportedError: (NotSupportedError) Variable_TypeByValue(): unhandled data
> type Integer 'SELECT max(cast(substr(azienda.codice_aziendale, :substr_1),
> :cast_1)) AS max_1 \nFROM azienda' {'substr_1': 2, 'cast_1': Integer()}
>
> -----------------
>
> the error is on func.cast, if I remove the cast function, it works:
>
> session.query(sa.func.max(sa.func.substr(Azienda.c.codice_aziendale,2))).filter(sa.func.REGEXP_LIKE(Azienda.c.data_inizio,
> '[[:digit:]]')).scalar()
>
> SELECT max(substr(azienda.codice_aziendale, :substr_1)) AS max_1
> FROM azienda
> WHERE REGEXP_LIKE(azienda.data_inizio, :REGEXP_LIKE_1)
>
> {'REGEXP_LIKE_1': '[[:digit:]]', 'substr_1': 2}
> Out[12]: u'_999'
>
>
> Michael Bayer wrote:
>> we would need to know what database you're using. It's likely your DB
>> doesn't support REGEXP_LIKE.
>>
>>
>> On Apr 18, 2012, at 4:00 AM, jo wrote:
>>
>>
>>> Hi all,
>>>
>>> Someone could help me with this query?
>>>
>>> SELECT MAX(CAST(SUBSTR(codice_aziendale, 2) AS INTEGER)) FROM azienda WHERE
>>> codice_aziendale LIKE '#%%' AND REGEXP_LIKE(SUBSTR(codice_aziendale, 2) ,
>>> '[[:digit:]]')
>>>
>>>
>>> I'm trying in this way:
>>>
>>> session.query(sa.func.max(sa.func.cast(sa.func.substr(Azienda.c.codice_aziendale,2),
>>> sa.Integer))).filter(sa.func.REGEXP_LIKE(Azienda.c.data_inizio,
>>> '[[:digit:]]')).scalar()
>>>
>>> but I got this error:
>>>
>>> NotSupportedError: (NotSupportedError) Variable_TypeByValue(): unhandled
>>> data type Integer 'SELECT max(cast(substr(azienda.codice_aziendale,
>>> :substr_1), :cast_1)) AS max_1 \nFROM azienda \nWHERE
>>> REGEXP_LIKE(azienda.data_inizio, :REGEXP_LIKE_1)' {'REGEXP_LIKE_1':
>>> '[[:digit:]]', 'substr_1': 2, 'cast_1': Integer()}
>>>
>>>
>>> j
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "sqlalchemy" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected].
>>> For more options, visit this group at
>>> http://groups.google.com/group/sqlalchemy?hl=en.
>>>
>>>
>>
>>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/sqlalchemy?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.