Yes, you're right.  Another developer was responsible for the "under the
hood" configuration of the UDID type, so I wasn't aware of the need to
coerce it in my case.  Coercing the UDID into a string as a parameter to
the from_statement works fine.

Thanks for help.
Kirk

On 8 March 2012 04:20, Michael Bayer <mike...@zzzcomputing.com> wrote:

>
> On Mar 7, 2012, at 10:39 AM, Kirk Holland wrote:
>
> Hi there,
>
> I have code that does this:
>
> Session.query(Region). \
> filter(Region.deleted==False). \
> filter(Region.region_id.in_(from_statement_query))
>
> Where "from_statement_query" is explicit SQL that returns only a region id.
>
> The SQL that is produced by this code looks like:
>
> SELECT region.region_id AS region_region_id, region.code AS region_code,
> region.name AS region_name, region.parent_id AS region_parent_id,
> region.deleted AS region_deleted
> FROM region
> WHERE region.deleted = %(deleted_1)s
> AND region.region_id IN (
>             select r2.region_id
>             from region_user ru,  region r2
>             where ru.user_id = %(user_id)s
>             and ru.region_id = r2.region_id
>       )
>
> {'user_id': UUID('01aefd99-d00d-4e7e-ac38-3f30f1f07326'), 'deleted_1':
> False}
>
> Which, when I replace the placeholders with the values indicated, runs
> perfectly well in psql.  However, SA is giving me the error:
>
> "ProgrammingError: (ProgrammingError) can't adapt type 'UUID'"
>
> The system is otherwise handling the UUID fields fine (they are in many
> tables and we can query, update, fetch etc without issue) but not in the
> case above.
>
> Any ideas?
>
>
> there's a uuid.UUID() value getting in there, which you definitely don't
> have in psql since that's a Python object.  If you need to pass in
> uuid.UUID(), you need to either make sure that bound parameter is using the
> sqlalchemy.dialects.postgresql.UUID type or another custom type that you've
> build to handle UUID() objects.   Otherwise you need to coerce it to a
> string before passing into the statement.
>
> If the issue is that the statement is aware of the UUID type and it's not
> coercing, then I'd need to see the mappings and how from_statement_query is
> constructed.
>
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> To unsubscribe from this group, send email to
> sqlalchemy+unsubscr...@googlegroups.com.
> 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 sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to