On Wednesday, November 13, 2013 4:48:47 PM UTC-8, Michael Bayer wrote:
[...]
>
> see attached for demo, should get you started
>

Thanks!  That was a tremendous help.  I've attached the version I ended up 
working with, using your code as a base.

The main changes, besides some names, are:

   - Changed 'output' to 'columns', which makes more sense.
   - If 'columns' contains strings, produce ColumnClause(name) for each 
   string as convenient shorthand.
   - Added column_map(self, iterable) as a shorthand to repeating 
   column_alias(self, from_, to) multiple times.
   - Add anonymous aliasing support like other aliases have.

This still doesn't entirely support all of that Postgres considers legal 
syntax -- e.g. these are both legal but can't currently be represented:

SELECT generate_series FROM generate_series(1, 100)
SELECT number FROM generate_series(1, 100) AS number

I'd kind of like to figure out how to support that for just for 
completeness sake (my idea was to trigger that behavior if no columns were 
specified), but I think it's a bad convention and would never use it in my 
own SQL anyways -- so it's not a priority for me.

The more interesting problem, I think, is to be able to determine the 
output column type based on input -- generate_series() can accept 
timestamps (and timestamp with time zones) in addition to ints/bigints, and 
the return value will be the same as the input parameters.  That said, I'm 
not entirely certain what benefit SQLAlchemy knowing the output column type 
provides.

I'm also not entirely happy that sqlalchemy.sql.expression.Alias() doesn't 
handle this correctly, but I'm under the impression that Aliases (as 
opposed to lowercase-a aliases) shouldn't be constructed directly anyways.

-- Daniel

-- 
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.

Reply via email to