Hi, I encounter a strange problem when I want to use subquery with
SQLElixir

This  is the model I have:
class Site(Entity):
    using_options(tablename='site')

    # site name in url
    site_name = Field(String(16), nullable=False, unique=True,
index=True)
    # the configuration of site
    config = Field(PickleType(comparator=_comparator))

    # admin of this site
    admin = ManyToOne('User', required=True)
    # sections of this site
    sections = OneToMany('Section')

class Section(Entity):
    using_options(tablename='section')

    # name to display
    display_name = Field(Unicode(256), nullable=False)
    # alias name in url
    section_name = Field(String(256), nullable=False, unique=True,
index=True)
    # the configuration of site
    config = Field(PickleType(comparator=_comparator))

    # the parent site
    site = ManyToOne('Site', required=True)
    # the parent section
    categories = OneToMany('Category')

class Category(Entity):
    using_options(tablename='category')

    # name to display
    display_name = Field(Unicode(256), nullable=False)
    # alias name in url
    category_name = Field(String(256), nullable=False)
    # the configuration of site
    config = Field(PickleType(comparator=_comparator))

    # the search index of this category
    search_index = Field(String(32), nullable=False)
    # key word to search
    keywords = Field(Unicode(256), nullable=False)

    # the parent section
    section = ManyToOne('Section')

And this is the query I do.

        site = model.Site.get(site)
        sections = db.session.query(model.Section.id).filter
(model.Section.site_id==site.id).subquery()
        categories = db.session.query(model.Category).filter
(model.Category.section_id.in_(sections))

I got a syntax error:

OperationalError: (OperationalError) near "SELECT": syntax error
u'SELECT count(1) AS count_1 \nFROM category, (SELECT section.id AS id
\nFROM section \nWHERE section.site_id = ?) AS anon_1 \nWHERE
category.section_id IN SELECT section.id \nFROM section \nWHERE
section.site_id = ?' [1, 1]

And then I tried to replace subquery with all(), and I got error:

InterfaceError: (InterfaceError) Error binding parameter 0 - probably
unsupported type. u'SELECT count(1) AS count_1 \nFROM category \nWHERE
category.section_id IN (?)' [(1,)]

It does not make sense. Why it query "SELECT count(1) AS count_1"
rather than category?
Could someone help me out?

Thanks.
Victor Lin.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"SQLElixir" 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/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to