Cache select query
See original GitHub issueHello guys. I used a simple code to print every n seconds result from db:
with pyodbc.connect(**odbcconnection) as cnxn:
cnxn.setdecoding(pyodbc.SQL_WCHAR, encoding='utf-8')
cnxn.setencoding(encoding='utf-8')
while True:
cursor = cnxn.cursor()
time.sleep(2)
cursor.execute("SELECT * FROM table GROUP by `name` DESC LIMIT 100")
rows = cursor.fetchall()
for row in rows:
print(row)
All ok, but if i change some information on db its nothing change when print show output Only if i restarted script i see a changed iformation
Whats i am doing wrong?! Thanks.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
8.10.3.2 Query Cache SELECT Options
SQL_CACHE. The query result is cached if it is cacheable and the value of the query_cache_type system variable is ON or DEMAND ....
Read more >CACHE SELECT | Databricks on AWS
Caches the data accessed by the specified simple SELECT query in the disk cache. You can choose a subset of columns to be...
Read more >Query Cache - MariaDB Knowledge Base
The query cache stores results of SELECT queries so that if the identical query is received in future, the results can be quickly...
Read more >Cached Queries | Caché SQL Optimization Guide
A cached query is created when certain SQL statements are prepared using ... SELECT: a SELECT cached query is shown in the Catalog...
Read more >What is query caching? How do I cache my query?
Cached Queries are a way for you to build applications with charts and tables that load instantly. A common use case for caching...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I was able to reproduce your issue under MySQL. You can ensure that you get the latest results by adding
at the end of your
while True:
loop.Without an
ORDER BY
clause on your SQL, the results from the query are indeterminate, particularly so with a LIMIT on it. Put anORDER BY
clause on the SQL query and try again.(also, minor point, but the line
cursor = cnxn.cursor()
does not need to be in the loop, it could be placed before thewhile
statement)