Python Forum
How to select NULL and blank values from MySQL table into csv
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to select NULL and blank values from MySQL table into csv
#1
Photo 
Hi all,

I am trying to select specific columns from a MySQL table into csv.
This table can have NULL or blank values and I want to differentiate between two when I extract.
Right now what's happening is that the extract has blank values for both NULL and blank values.

Is there any recommended way to do this?

import mysql.connector

mydb = mysql.connector.connect(
    host="host",
    user="user",
    password="pwd",
)

mycursor = mydb.cursor()

mycursor.execute("select * from db_name.table_name")

myresult = mycursor.fetchall()

for x in myresult:
    print(x)
Somehow formatting is not working for me so can't conver code into code snippet or insert images but trying my best.
The above is printing both blank and NULL values same: blank
File produced is this way, no diff between the NULL and Blanks values:
   
|2020-09-18 02:48:04|||||||||
Reply


Messages In This Thread
How to select NULL and blank values from MySQL table into csv - by python300 - Dec-19-2022, 07:05 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Mysql and mysql.connector error lostintime 2 836 Oct-03-2023, 10:25 PM
Last Post: lostintime
  How to express null value klatlap 3 985 Mar-25-2023, 10:40 AM
Last Post: klatlap
  Replacing values ​​in Mysql with a condition stsxbel 0 699 Mar-05-2023, 08:20 PM
Last Post: stsxbel
  Mysql Workbench table not updated CatBall 2 1,237 Feb-13-2023, 05:37 PM
Last Post: CatBall
  Write Null values as 0.0 (float) type in csv mg24 3 1,554 Dec-07-2022, 09:04 PM
Last Post: deanhystad
  store all variable values into list and insert to sql_summary table mg24 3 1,256 Sep-28-2022, 09:13 AM
Last Post: Larz60+
  Mysql error message: Lost connection to MySQL server during query tomtom 6 16,760 Feb-09-2022, 09:55 AM
Last Post: ibreeden
  value null when update in json file 3lnyn0 6 3,709 Dec-30-2021, 05:52 PM
Last Post: ndc85430
  Sum the values in a pandas pivot table specific columns klllmmm 1 4,832 Nov-19-2021, 04:43 PM
Last Post: klllmmm
  SaltStack: MySQL returner save less data into Database table columns xtc14 2 2,261 Jul-02-2021, 02:19 PM
Last Post: xtc14

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020