werner wrote:
>
> q2 = session.query(stAlias2).outerjoin((stAlias2,
> stAlias2.code_id==stAlias3.code_id),
this is going to render
select * from <alias2> left outer join <alias2> on
<alias2>.code_id==<alias3>.code_id
i.e. renders <alias2> twice in the FROM
> (stAlias3,
> stAlias3.lang_code5=='FR_fr')
> ).filter(db.sa.and_(
> stAlias2.lang_code5=='EN_en',
> stAlias3.id==db.sa.null()))
>
> q3 = q1.union(q2)
>
> print q3
> print '================'
> print q3.all()
>
> I am probably overusing "alias" but it makes it clearer to me to match
> with the original sql.
>
> However I am getting the following exception as "somecode_t_1" and
> "somecode_t_2" use the same column aliases, what am I doing wrong that
> this is happening?
>
> Werner
>
> Traceback (most recent call last):
> File "saTest.py", line 102, in <module>
> print q3.all()
> File
> "c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\orm\query.py",
> line 1267, in all
> return list(self)
> File
> "c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\orm\query.py",
> line 1361, in __iter__
> return self._execute_and_instances(context)
> File
> "c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\orm\query.py",
> line 1364, in _execute_and_instances
> result = self.session.execute(querycontext.statement,
> params=self._params, mapper=self._mapper_zero_or_none())
> File
> "c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\orm\session.py",
> line 753, in execute
> clause, params or {})
> File
> "c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\engine\base.py",
> line 824, in execute
> return Connection.executors[c](self, object, multiparams, params)
> File
> "c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\engine\base.py",
> line 874, in _execute_clauseelement
> return self.__execute_context(context)
> File
> "c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\engine\base.py",
> line 896, in __execute_context
> self._cursor_execute(context.cursor, context.statement,
> context.parameters[0], context=context)
> File
> "c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\engine\base.py",
> line 950, in _cursor_execute
> self._handle_dbapi_exception(e, statement, parameters, cursor,
> context)
> File
> "c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\engine\base.py",
> line 931, in _handle_dbapi_exception
> raise exc.DBAPIError.instance(statement, parameters, e,
> connection_invalidated=is_disconnect)
> sqlalchemy.exc.ProgrammingError: (ProgrammingError) (-204,
> 'isc_dsql_prepare: \n Dynamic SQL Error\n SQL error code = -204\n
> alias ANON_1 SOMECODE_T_2 conflicts with an alias in the same
> statement') 'SELECT anon_1.id AS anon_1_id, anon_1.code_id AS
> anon_1_code_id, anon_1.lang_code5 AS anon_1_lang_code5, anon_1.name AS
> anon_1_name, anon_1.short_name AS anon_1_short_name, anon_1.created_at
> AS anon_1_created_at, anon_1.updated_at AS anon_1_updated_at \nFROM
> (SELECT somecode_t_1.id AS id, somecode_t_1.code_id AS code_id,
> somecode_t_1.lang_code5 AS lang_code5, somecode_t_1.name AS name,
> somecode_t_1.short_name AS short_name, somecode_t_1.created_at AS
> created_at, somecode_t_1.updated_at AS updated_at \nFROM somecode_t
> somecode_t_1 \nWHERE somecode_t_1.lang_code5 = ? UNION SELECT
> somecode_t_2.id AS id, somecode_t_2.code_id AS code_id,
> somecode_t_2.lang_code5 AS lang_code5, somecode_t_2.name AS name,
> somecode_t_2.short_name AS short_name, somecode_t_2.created_at AS
> created_at, somecode_t_2.updated_at AS updated_at \nFROM somecode_t
> somecode_t_2 LEFT OUTER JOIN somecode_t somecode_t_2 ON
> somecode_t_2.code_id = somecode_t_3.code_id LEFT OUTER JOIN somecode_t
> somecode_t_3 ON somecode_t_3.lang_code5 = ? \nWHERE
> somecode_t_2.lang_code5 = ? AND somecode_t_3.id IS NULL) anon_1'
> ['FR_fr', 'FR_fr', 'EN_en']
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To post to this group, send email to [email protected].
> 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.
>
>
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
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.