On Apr 25, 8:46 am, Michael Bayer <[EMAIL PROTECTED]> wrote: > On Apr 25, 2008, at 9:04 AM, Luke Iannini wrote: > > > > > > > Hi all, > > Is there a way to use generate_series with SQLAlchemy? > > >http://www.postgresql.org/docs/8.2/interactive/functions-srf.html > > > generate_series = select([column('i')], > > from_obj=[func.generate_series(bindparam('start'), > > bindparam('end'))]) > > > zrows = select([generate_series.params(start=1, > > end=20).c.i]).label('series') > > > is the best stab I've made at it, but I don't actually understand the > > syntax in the PGSQL docs: > > > select current_date + s.a as dates from generate_series(0,14,7) as > > s(a); > > that particular syntax is an aliasing syntax that we plan on > supporting in the near future, so the above would look possibly like > > s = func.generate_series(4,5,6).alias(cols=['a']) > > select([func.current_date() + s.c.a]) > > you can hardwire this stuff using text right now: > > select([(func.current_date() + > literal_column > ("s.a")).label("dates")]).select_from("generate_series(0, 14, 7) as > s(a)") Thanks so much Michael! That worked perfectly.
> I just noticed that the text() construct, which would allow the > bindparams to happen, is not being accepted into select_from() so i've > added ticket #1014 for that. > > > As a side question, how would I add static columns to a select > > statement? e.g. based on the pseudocode above: > > zrows = select([generate_series.params(start=1, end=20).c.i], 0, 0, > > 0).label('series') > > to add 3 columns of 0 value to each row generated. > > you should be able to put plain strings in the columns clause: > > select(["foo", "bar", "bat"]) > > this is shorthand for using the "literal_column()" construct which you > can use anywhere in a column expression to produce textual SQL > expressions. Got it. Thanks again Cheers Luke --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---