<s> from sqlalchemy . testing import fixtures <EOL> from sqlalchemy . testing import AssertsCompiledSQL , assert_raises_message <EOL> from sqlalchemy . sql import select , func <EOL> from sqlalchemy . engine import default <EOL> from sqlalchemy import exc <EOL> from sqlalchemy import Table , Integer , String , ForeignKey , Column , true <EOL> from sqlalchemy import lateral , outerjoin , join <EOL> class LateralTest ( fixtures . TablesTest , AssertsCompiledSQL ) : <EOL> __dialect__ = default . DefaultDialect ( supports_native_boolean = True ) <EOL> run_setup_bind = None <EOL> run_create_tables = None <EOL> @ classmethod <EOL> def define_tables ( cls , metadata ) : <EOL> Table ( '<STR_LIT>' , metadata , <EOL> Column ( '<STR_LIT>' , Integer , primary_key = True ) , <EOL> Column ( '<STR_LIT>' , Integer ) , <EOL> Column ( '<STR_LIT:name>' , String ( <NUM_LIT:30> ) ) ) <EOL> Table ( '<STR_LIT>' , metadata , <EOL> Column ( '<STR_LIT>' , Integer , primary_key = True ) , <EOL> Column ( <EOL> '<STR_LIT>' , <EOL> Integer , ForeignKey ( '<STR_LIT>' ) ) , <EOL> Column ( '<STR_LIT>' , Integer ) , <EOL> Column ( '<STR_LIT>' , Integer ) ) <EOL> Table ( '<STR_LIT>' , metadata , <EOL> Column ( '<STR_LIT>' , Integer , primary_key = True ) , <EOL> Column ( <EOL> '<STR_LIT>' , Integer , ForeignKey ( '<STR_LIT>' ) ) , <EOL> Column ( '<STR_LIT>' , Integer , ForeignKey ( '<STR_LIT>' ) ) , <EOL> Column ( '<STR_LIT>' , Integer ) ) <EOL> def test_standalone ( self ) : <EOL> table1 = self . tables . people <EOL> subq = select ( [ table1 . c . people_id ] ) <EOL> self . assert_compile ( <EOL> lateral ( subq , name = "<STR_LIT>" ) , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assert_compile ( <EOL> subq . lateral ( name = "<STR_LIT>" ) , <EOL> '<STR_LIT>' <EOL> ) <EOL> def test_select_from ( self ) : <EOL> table1 = self . tables . people <EOL> subq = select ( [ table1 . c . people_id ] ) <EOL> self . assert_compile ( <EOL> select ( [ subq . lateral ( name = '<STR_LIT>' ) ] ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> def test_plain_join ( self ) : <EOL> table1 = self . tables . people <EOL> table2 = self . tables . books <EOL> subq = select ( [ table2 . c . book_id ] ) . where ( table2 . c . book_owner_id == table1 . c . people_id ) <EOL> self . assert_compile ( <EOL> join ( table1 , lateral ( subq , name = "<STR_LIT>" ) , true ( ) ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> self . assert_compile ( <EOL> select ( [ table1 ] ) . select_from ( <EOL> join ( table1 , lateral ( subq , name = "<STR_LIT>" ) , true ( ) ) <EOL> ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> subq = subq . correlate ( table1 ) <EOL> self . assert_compile ( <EOL> select ( [ table1 ] ) . select_from ( <EOL> join ( table1 , lateral ( subq , name = "<STR_LIT>" ) , true ( ) ) <EOL> ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_join_lateral_w_select_subquery ( self ) : <EOL> table1 = self . tables . people <EOL> table2 = self . tables . books <EOL> subq = select ( [ table2 . c . book_id ] ) . correlate ( table1 ) . where ( table1 . c . people_id == table2 . c . book_owner_id ) . lateral ( ) <EOL> stmt = select ( [ table1 , subq . c . book_id ] ) . select_from ( table1 . join ( subq , true ( ) ) ) <EOL> self . assert_compile ( <EOL> stmt , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_from_function ( self ) : <EOL> bookcases = self . tables . bookcases <EOL> srf = lateral ( func . generate_series ( <NUM_LIT:1> , bookcases . c . bookcase_shelves ) ) <EOL> self . assert_compile ( <EOL> select ( [ bookcases ] ) . select_from ( bookcases . join ( srf , true ( ) ) ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) </s>
