Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8348283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:38:46+00:00 2026-06-09T07:38:46+00:00

I am new to SQLAlchemy and I am trying to achieve this SQL: SELECT

  • 0

I am new to SQLAlchemy and I am trying to achieve this SQL:

SELECT 
    node.*,
    alarms.*
FROM
    node
        LEFT JOIN
            alarms ON alarms.nodeid = node.nodeid 
WHERE
    node.foreignid IN ('foreignid_1','foreignid_2','foreignid_3') 
ORDER BY node.nodeid;

I come up with this statement:

stmt = session.query(Node, Alarms).outerjoin(Alarms, Alarms.nodeid == Node.nodeid).filter(Node.foreignid.in_(['foreignid_1','foreignid_2','foreignid_3'])).order_by(asc(Node.nodeid))
results = stmt.all()

The generated SQL looks like:

SELECT 
    node.nodeid AS node_nodeid,
    node.dpname AS node_dpname,
    node.nodecreatetime AS node_nodecreatetime,
    node.nodeparentid AS node_nodeparentid,
    node.nodetype AS node_nodetype,
    node.nodesysoid AS node_nodesysoid,
    node.nodesysname AS node_nodesysname,
    node.nodesysdescription AS node_nodesysdescription,
    node.nodesyslocation AS node_nodesyslocation,
    node.nodesyscontact AS node_nodesyscontact,
    node.nodelabel AS node_nodelabel,
    node.nodelabelsource AS node_nodelabelsource,
    node.nodenetbiosname AS node_nodenetbiosname,
    node.nodedomainname AS node_nodedomainname,
    node.operatingsystem AS node_operatingsystem,
    node.lastcapsdpoll AS node_lastcapsdpoll,
    node.foreignsource AS node_foreignsource,
    node.foreignid AS node_foreignid,
    alarms.alarmid AS alarms_alarmid,
    alarms.eventuei AS alarms_eventuei,
    alarms.dpname AS alarms_dpname,
    alarms.nodeid AS alarms_nodeid,
    alarms.ipaddr AS alarms_ipaddr,
    alarms.serviceid AS alarms_serviceid,
    alarms.reductionkey AS alarms_reductionkey,
    alarms.alarmtype AS alarms_alarmtype,
    alarms.counter AS alarms_counter,
    alarms.severity AS alarms_severity,
    alarms.lasteventid AS alarms_lasteventid,
    alarms.firsteventtime AS alarms_firsteventtime,
    alarms.lasteventtime AS alarms_lasteventtime,
    alarms.firstautomationtime AS alarms_firstautomationtime,
    alarms.lastautomationtime AS alarms_lastautomationtime,
    alarms.description AS alarms_description,
    alarms.logmsg AS alarms_logmsg,
    alarms.operinstruct AS alarms_operinstruct,
    alarms.tticketid AS alarms_tticketid,
    alarms.tticketstate AS alarms_tticketstate,
    alarms.mouseovertext AS alarms_mouseovertext,
    alarms.suppresseduntil AS alarms_suppresseduntil,
    alarms.suppresseduser AS alarms_suppresseduser,
    alarms.suppressedtime AS alarms_suppressedtime,
    alarms.alarmackuser AS alarms_alarmackuser,
    alarms.alarmacktime AS alarms_alarmacktime,
    alarms.managedobjectinstance AS alarms_managedobjectinstance,
    alarms.managedobjecttype AS alarms_managedobjecttype,
    alarms.applicationdn AS alarms_applicationdn,
    alarms.ossprimarykey AS alarms_ossprimarykey,
    alarms.x733alarmtype AS alarms_x733alarmtype,
    alarms.x733probablecause AS alarms_x733probablecause,
    alarms.qosalarmstate AS alarms_qosalarmstate,
    alarms.clearkey AS alarms_clearkey,
    alarms.ifindex AS alarms_ifindex,
    alarms.eventparms AS alarms_eventparms
FROM
    node
        LEFT OUTER JOIN
            alarms ON alarms.nodeid = node.nodeid
WHERE
    node.foreignid IN ('foreignid_2' , 'foreignid_1', 'foreignid_3')
ORDER BY node.nodeid ASC  

But it also throws this error (from iPython):

In [86]: stmt = session.query(Node, Alarms).outerjoin(Alarms, Alarms.nodeid == Node.nodeid).filter(Node.foreignid.in_(['foreignid_1','foreignid_3','foreignid_2'])).order_by(asc(Node.nodeid))

In [87]: results = stmt.all()
---------------------------------------------------------------------------
InternalError                             Traceback (most recent call last)
<ipython-input-87-1110c354b407> in <module>()
----> 1 results = stmt.all()

/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.8-py2.6-linux-x86_64.egg/sqlalchemy/orm/query.pyc in all(self)
   2113
   2114         """
-> 2115         return list(self)
   2116
   2117     @_generative(_no_clauseelement_condition)

/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.8-py2.6-linux-x86_64.egg/sqlalchemy/orm/query.pyc in __iter__(self)
   2225         if self._autoflush and not self._populate_existing:
   2226             self.session._autoflush()
-> 2227         return self._execute_and_instances(context)
   2228
   2229     def _connection_from_session(self, **kw):

/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.8-py2.6-linux-x86_64.egg/sqlalchemy/orm/query.pyc in _execute_and_instances(self, querycontext)
   2240                         close_with_result=True)
   2241
-> 2242         result = conn.execute(querycontext.statement, self._params)
   2243         return self.instances(result, querycontext)
   2244

/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.8-py2.6-linux-x86_64.egg/sqlalchemy/engine/base.pyc in execute(self, object, *multiparams, **params)
   1447                                                 object,
   1448                                                 multiparams,
-> 1449                                                 params)
   1450         else:
   1451             raise exc.InvalidRequestError(

/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.8-py2.6-linux-x86_64.egg/sqlalchemy/engine/base.pyc in _execute_clauseelement(self, elem, multiparams, params)
   1582             compiled_sql,
   1583             distilled_params,
-> 1584             compiled_sql, distilled_params
   1585         )
   1586         if self._has_events:

/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.8-py2.6-linux-x86_64.egg/sqlalchemy/engine/base.pyc in _execute_context(self, dialect, constructor, statement, parameters, *args)
   1696                                 parameters,
   1697                                 cursor,
-> 1698                                 context)
   1699             raise
   1700

/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.8-py2.6-linux-x86_64.egg/sqlalchemy/engine/base.pyc in _execute_context(self, dialect, constructor, statement, parameters, *args)
   1689                                     statement,
   1690                                     parameters,
-> 1691                                     context)
   1692         except Exception, e:
   1693             self._handle_dbapi_exception(

/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.8-py2.6-linux-x86_64.egg/sqlalchemy/engine/default.pyc in do_execute(self, cursor, statement, parameters, context)
    329
    330     def do_execute(self, cursor, statement, parameters, context=None):
--> 331         cursor.execute(statement, parameters)
    332
    333     def do_execute_no_params(self, cursor, statement, context=None):

InternalError: (InternalError) current transaction is aborted, commands ignored until end of transaction block
 'SELECT node.nodeid AS node_nodeid, node.dpname AS node_dpname, node.nodecreatetime AS node_nodecreatetime, node.nodeparentid AS node_nodeparentid, node.nodetype AS node_nodetype, node.nodesysoid AS node_nodesysoid, node.nodesysname AS node_nodesysname, node.nodesysdescription AS node_nodesysdescription, node.nodesyslocation AS node_nodesyslocation, node.nodesyscontact AS node_nodesyscontact, node.nodelabel AS node_nodelabel, node.nodelabelsource AS node_nodelabelsource, node.nodenetbiosname AS node_nodenetbiosname, node.nodedomainname AS node_nodedomainname, node.operatingsystem AS node_operatingsystem, node.lastcapsdpoll AS node_lastcapsdpoll, node.foreignsource AS node_foreignsource, node.foreignid AS node_foreignid, alarms.alarmid AS alarms_alarmid, alarms.eventuei AS alarms_eventuei, alarms.dpname AS alarms_dpname, alarms.nodeid AS alarms_nodeid, alarms.ipaddr AS alarms_ipaddr, alarms.serviceid AS alarms_serviceid, alarms.reductionkey AS alarms_reductionkey, alarms.alarmtype AS alarms_alarmtype, alarms.counter AS alarms_counter, alarms.severity AS alarms_severity, alarms.lasteventid AS alarms_lasteventid, alarms.firsteventtime AS alarms_firsteventtime, alarms.lasteventtime AS alarms_lasteventtime, alarms.firstautomationtime AS alarms_firstautomationtime, alarms.lastautomationtime AS alarms_lastautomationtime, alarms.description AS alarms_description, alarms.logmsg AS alarms_logmsg, alarms.operinstruct AS alarms_operinstruct, alarms.tticketid AS alarms_tticketid, alarms.tticketstate AS alarms_tticketstate, alarms.mouseovertext AS alarms_mouseovertext, alarms.suppresseduntil AS alarms_suppresseduntil, alarms.suppresseduser AS alarms_suppresseduser, alarms.suppressedtime AS alarms_suppressedtime, alarms.alarmackuser AS alarms_alarmackuser, alarms.alarmacktime AS alarms_alarmacktime, alarms.managedobjectinstance AS alarms_managedobjectinstance, alarms.managedobjecttype AS alarms_managedobjecttype, alarms.applicationdn AS alarms_applicationdn, alarms.ossprimarykey AS alarms_ossprimarykey, alarms.x733alarmtype AS alarms_x733alarmtype, alarms.x733probablecause AS alarms_x733probablecause, alarms.qosalarmstate AS alarms_qosalarmstate, alarms.clearkey AS alarms_clearkey, alarms.ifindex AS alarms_ifindex, alarms.eventparms AS alarms_eventparms \nFROM node LEFT OUTER JOIN alarms ON alarms.nodeid = node.nodeid \nWHERE node.foreignid IN (%(foreignid_1)s, %(foreignid_2)s, %(foreignid_3)s) ORDER BY node.nodeid ASC' {'foreignid_1': 'foreignid_1', 'foreignid_3': 'foreignid_3', 'foreignid_2': 'foreignid_2'}

I just don’t understand what is the error while the generated SQL is good.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T07:38:47+00:00Added an answer on June 9, 2026 at 7:38 am

    Your exception has nothing to do with your generated SQL, which is exactly what you wanted.

    Your database connection is in the wrong state; a transaction was aborted (probably due to an integrity error somewhere) and no new transaction was started, and your database didn’t like that.

    While experimenting with SQLAlchemy from an iPython prompt, it’s probably better to turn auto-commit on, so you don’t have to deal with the intricacies of transaction management.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to sqlalchemy, and I'm trying to achieve simple validation of model's fields,
New to PHP and MySQL, have heard amazing things about this website from Leo
New to Node.js and Express, I am trying to understand the two seems overlapping
Using SQLAlchemy, an Engine object is created like this: from sqlalchemy import create_engine engine
Python noob here, Currently I'm working with SQLAlchemy, and I have this: from __init__
I'm new at SQLAlchemy and migrations. Basically, what I understand it this: Create base
I'm pretty new to sqlalchemy and oracle. I'm trying to perform a query on
I'm new to sqlalchemy and could use some help. I'm trying to write a
I'm new to sqlalchemy and am trying to map several tables to a class.
I am trying to select all the records from a sqlite db I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.