I think if you give your func.xpath a datatype of pg.ARRAY(of whatever) you’ll get it:
func.xpath(…, type_=postgresql.ARRAY)[1] >>> from sqlalchemy import func, String >>> from sqlalchemy.dialects import postgresql >>> print func.xpath('something', 'somethingelse', >>> type_=postgresql.ARRAY(String()))[1].compile(dialect=postgresql.dialect()) xpath(%(xpath_1)s, %(xpath_2)s)[%(xpath_3)s] >>> On Dec 5, 2013, at 3:33 PM, Christian Lang <christian.a.l...@gmail.com> wrote: > Hi, > > I'm trying to create the following index (on PostgreSQL) with SQLAlchemy 0.8: > > CREATE INDEX doc_idx ON xmltab (CAST((xpath('//@bla', doc))[1] AS TEXT)); > > (where doc is a column of type XML) > > I got this far: > > Index("doc_idx", cast((func.xpath('//@bla', xmlTable.c.doc))[1], TEXT)) > > but get the error: > Traceback (most recent call last): > File "xmltests.py", line 146, in <module> > idx = Index("doc_idx", cast((func.xpath('//@bla', xmlTable.c.doc))[1], > TEXT)) > File "build/bdist.linux-x86_64/egg/sqlalchemy/sql/operators.py", line 320, > in __getitem__ > File "build/bdist.linux-x86_64/egg/sqlalchemy/sql/expression.py", line > 2311, in operate > File "build/bdist.linux-x86_64/egg/sqlalchemy/sql/operators.py", line 320, > in __getitem__ > File "build/bdist.linux-x86_64/egg/sqlalchemy/sql/expression.py", line > 1994, in operate > File "build/bdist.linux-x86_64/egg/sqlalchemy/sql/expression.py", line > 2148, in _unsupported_impl > NotImplementedError: Operator 'getitem' is not supported on this expression > > It seems getitem should be allowed since the xpath expression returns an > array of nodes (and it is fine in PostgreSQL). > Any idea what I am doing wrong and how to fix it? > > Thanks, > Christian > > > -- > 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 sqlalchemy+unsubscr...@googlegroups.com. > To post to this group, send email to sqlalchemy@googlegroups.com. > Visit this group at http://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/groups/opt_out.
signature.asc
Description: Message signed with OpenPGP using GPGMail