CROSS JOIN just means a JOIN that has no WHERE clause, so the implicit selection of both tables is fine as well. LATERAL we now support but AFAIK it just allows the joined expression to refer to the FROM clause, which isn't the case in at least this example.

To get the "generate_series()" thing cleanly as a FROM object, there's some recipes at https://bitbucket.org/zzzeek/sqlalchemy/issues/3566/figure-out-how-to-support-all-of-pgs that will deal with PG's syntaxes directly and will work here too. Using the recipe at https://bitbucket.org/zzzeek/sqlalchemy/issues/3566/figure-out-how-to-support-all-of-pgs#comment-22842678, with a little tweak, i can make that statement:


class generate_series(ColumnFunction):
    name = 'generate_series'

    def alias(self, name):
        self.column_names = [name]
        return super(generate_series, self).alias(name)

x = generate_series(1, 2).alias('x')
y = generate_series(1, 2).alias('y')

from sqlalchemy import select
stmt = select([x.c.x, y.c.y]).select_from(x).select_from(y)

print stmt







On 07/09/2016 08:07 AM, Priit Laes wrote:
Hi!

I've been struggling to convert queries below to SQLAlchemy core (
1.1.0 beta2):

SELECT x,y FROM generate_series(1,2) AS x, generate_series(1,2) as y;
 x | y
---+---
 1 | 1
 1 | 2
 2 | 1
 2 | 2
(4 rows)

This query seems to be a shorthand version of this below (though I'm
not 100% sure whether the short version isn't just an accidental case
of ambigious query):

SELECT x, y FROM generate_series(1, 2) AS x
        CROSS JOIN LATERAL generate_series(1, 2) AS y;

CROSS JOIN seems to be currently unimplemented.


Päikest,
Priit Laes :)


--
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to