I have a DB and when I query a table I get 67 results. The SQL is: I try to connect to the DB, and I get no connection errors. It prints out -1 for rowcount. The connection to the DB appears to be working, the SQL is a simple query… Answer Try adding cursor.fetchall() before the print(cursor.rowcount)
Tag: python
SQL want efficient query to SELECT columnA, columnB FROM table1 WHERE both columnA, columnB are in columnC FROM table2 WHERE columndD > value
I’m searching for a more efficient method to accomplish something that I’ve already solved with a few different SQL statements. The problem: I have two tables a transactions table, and an accounts table The transactions table has columns that look like: acct_sending acct_receiving amount tx_datetime 100 101 10 yyyy-mm-dd hh-mm-ss 101 100 5 yyyy-mm-dd hh-mm-ss 101 200 1 yyyy-mm-dd hh-mm-ss
How can i use value of a combobox in another external file to help cursor.excute to search in database? NameError: name ‘combo1’ is not defined
I’m having trouble using the combobox in an external file. Basically the combobox is in the main file and I would like to use its selected value in the external file. If I select a certain item, it should help cursor.excute to search for a database table, so cursor.execute(“SELECT x FROM Table1 WHERE element = ?”, (combo1,)) As you can
I’m trying to insert rows into a database using executemany but rows not showing in database after executing code
Answer When I ran your code, I was able to query the database. It correctly inserted the items.
Dynamanically add column(s) and insert values into a Sqlite TABLE from json objects
I am using the Python tweepy library to scrap and collect tweet data for a research purpose. Specifically is use tweepy.StreamingClient class to get tweet the from stream. Returned data is json object whose elements depends on the data fields available with retrieved tweet post. So for example, at one time I received json object with few elements like this:
Python SqlAlchemy adding escape characters to json string while inserting in postgresql json column, so queries not working
I am adding JSON string to Postgres jsonb column in python using the sqlalchemy library. Code to create json string is Code to add to postgresql database is: My JSON is printed properly in logs But when it goes to database the json is enclosed in a string and an escape character is added in front of every double quote.
DuckDB – efficiently insert pandas dataframe to table with sequence
Insertion with series works just fine: How I can use the sequence with pandas dataframe? I don’t want to iterate item by item. The goal is to efficiently insert 1000s of items from python to DB. I’m ok to change pandas to something else. Answer Can’t you have nextval(‘serial’) as part of your select query when reading the df? e.g.,
Splitting each Multi-Category columns to Multiple columns with counts
date Value1 Value2 Value3 16-08-2022 a b e 16-08-2022 a b f 16-08-2022 c d f output date Value1_a Value1_c Value2_b Value2_d Value3_e Value3_f 16-08-2022 2 1 2 1 1 2 continues like this for more columns maybe 10, I will aggregate on date and split the categorical columns with counts for each category , currently doing like this Need
Adding a set to a database table, using format string – how to include null values
I have a set that depending on the situation can contain anywhere between 1 and 5 elements. I am saving this set to a database table using a format string. My table contains 5 tables, but when creating it, I did include that it was okay to have null values in the columns. my set below can be: but it
How to union two counts queries in SQLAlchemy?
I have two queries and the only difference between then is that one is counting the success status and the other failure status. Is there a way to get this result in just one query? I’m using SQLALchemy to do the queries. Answer You can use conditions on Count, your query will look like: