0

While trying to update a non-existing column in a single statement throws an exception:

session.execute("UPDATE users SET wrong_column = [email protected];")

If I do the same with multiple statements, the exception is not raised:

session.execute("UPDATE users SET email = [email protected]; UPDATE users SET wrong_column = [email protected];")

One stackoverflow solution proposed is to split the query by the delimiter ;:

But this does not work in my particular case as my query also consist of a few functions that have a delimiter in the RETURN ... ; statement and then again the END; statement, so the split would break the query. (I know I could also try to split the query with sqlparse but installing an extra library for that also seems weird to me)

Is there really no better way to check if all statements in a raw query were executed without error?

I also tried to find something in the CursorResult object that is returned by the session.execute func, but I could not find anything.

(I'm working with a MySQL DB in case it matters)

2
  • 2
    I can't find any supportive docs, but my gut feel is that execute is designed for single statements. If you want to execute multiple text statements you might be better off using the DB-API cursor, as shown in some of the answers to the Q&A that you linked. Commented Feb 9, 2023 at 19:26
  • Thanks @snakecharmerb This worked totally fine: ``` cursor = db_session.connection().connection.cursor() cursor.execute(query) ``` Commented Feb 27, 2023 at 12:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.