Using SQL aggregate fcns on a PGArray column

10 views
Skip to first unread message

David Korz

unread,
Jun 11, 2010, 8:55:05 PM6/11/10
to sqlalchemy
I have a table like such:

CREATE TABLE test (
mykey integer not null,
mydata double precision [2][10]
) without oids;

with a table defn like:

test = Table("test",metadata,
Column("mykey",Integer,nullable=False),
Column("mydata",PGArray(Float))
)

I want to do a query like:

select mykey,sum(mydata[1][1]) from test group by mykey;

In SA I want to do something like:

query = select([test.c.mykey,func.sum(test.c.mydata[1]
[1])],from_obj=[test]).group_by(test.c.mykey)

test.c.mydata can't be indexed so this is illegal. Is there a way I
can access an array element in SA without just putting the actual SQL
text in?

Michael Bayer

unread,
Jun 12, 2010, 8:18:03 PM6/12/10
to sqlal...@googlegroups.com

This is an unimplemented feature at the moment. I've created a recipe that hand-rolls the syntax plus typing behavior as a @compiles recipe, which is available at: http://www.sqlalchemy.org/trac/wiki/UsageRecipes/PGArrayIndex .


Reply all
Reply to author
Forward
0 new messages