skip to Main Content

I’m attempting to retrieve all the data from a column in mysql by having the user input which table and column the data is through the mysqlconnector library in python. When I ran the query through python no data would show up and then when I ran it through Phpmyadmin I would get these errors:

Warning: #1292 Truncated incorrect DOUBLE value: 'Matisse'
Warning: #1292 Truncated incorrect DOUBLE value: 'Picasso'
Warning: #1292 Truncated incorrect DOUBLE value: 'van Gogh'
Warning: #1292 Truncated incorrect DOUBLE value: 'Deli'

I found the query only works for columns that are integer based and does not work for date-time or varchar columns (The L_Name one from which the query doesn’t work is varchar(25).

Here is the query:

SELECT * FROM `artist` WHERE L_Name

After the query is run and throws those errors, the query changes to this by itself:

SELECT * FROM `artist` WHERE 1

This new query returns the whole table and all of its columns and rows but of course all I want is for it to simply return the single column.

EDIT: To clarify, the point of running the SELECT * FROM `artist` WHERE L_Name
query is to bring up the whole list of values in that column for that table. This is just one case and there’s many other cases like if the user wanted to search up a specific record from the art_show table and then look at all the values in the column of the gallery location.

2

Answers


  1. Chosen as BEST ANSWER

    Figured out the solution. My Python had an issue where it would only print the first value due to how I set up the print statement. Fixed it by changing the query on the 3rd line and also changing the print statement from print(rec[0]) to print(rec)

    def show_entries(table, column):
        print(f"Here's the records in the table {table} and the column {column}.")
        mycursor.execute(f"SELECT {column} FROM {table}")
        myresult = mycursor.fetchall()
        for rec in myresult:
            print(rec)
    

  2. I don’t think its the error thats the problem since you did varchar, maybe check your python code?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search