Hi everyone,
I am trying to set up the st.experimental_connections to a MySQL database. To read from the database works, but writing always give the Error:
ArgumentError: Textual SQL expression ‘INSERT INTO document (ID,…’ should be explicitly declared as text(‘INSERT INTO document (ID,…’)
My Code
connection = st.experimental_connection(name = 'ghost', type = 'sql', autocommit = True)
with connection.session as session:
session.execute('INSERT INTO document (ID, SENTENCE) VALUES(:id, :sen);', params = dict(id = id, sen = answer))
session.commit()
2023-09-29 16:51:43.113 Uncaught app exception
Traceback (most recent call last):
File “/Users/ben/miniconda3/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py”, line 541, in _run_script
exec(code, module.dict)
File “/Users/ben/Library/Mobile Documents/com~apple~CloudDocs/Python/Streamlit/Ghostwriter/ghost.py”, line 115, in
session.execute(‘INSERT INTO document (ID, SENTENCE) VALUES(:id, :sen);’, {“id”: id, “sen”: answer})
File “/Users/ben/miniconda3/lib/python3.10/site-packages/sqlalchemy/orm/session.py”, line 2262, in execute
return self._execute_internal(
File “/Users/ben/miniconda3/lib/python3.10/site-packages/sqlalchemy/orm/session.py”, line 2042, in _execute_internal
statement = coercions.expect(roles.StatementRole, statement)
File “/Users/ben/miniconda3/lib/python3.10/site-packages/sqlalchemy/sql/coercions.py”, line 413, in expect
resolved = impl._literal_coercion(
File “/Users/ben/miniconda3/lib/python3.10/site-packages/sqlalchemy/sql/coercions.py”, line 638, in _literal_coercion
return self._text_coercion(element, argname, **kw)
File “/Users/ben/miniconda3/lib/python3.10/site-packages/sqlalchemy/sql/coercions.py”, line 631, in _text_coercion
return _no_text_coercion(element, argname)
File “/Users/ben/miniconda3/lib/python3.10/site-packages/sqlalchemy/sql/coercions.py”, line 601, in _no_text_coercion
raise exc_cls(
sqlalchemy.exc.ArgumentError: Textual SQL expression ‘INSERT INTO document (ID,…’ should be explicitly declared as text(‘INSERT INTO document (ID,…’)
that worked… I am just surprised as I thought that I already tried this many times before.
Whatever, thanks a lot!
Ben
Hello there 👋🏻
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.