cancel
Showing results for 
Search instead for 
Did you mean: 
Community Discussions
cancel
Showing results for 
Search instead for 
Did you mean: 

Query results in csv file include 'null' string for blank cell

AlexG
New Contributor II

After running a sql script, when downloading the results to a csv file, the file includes a null string for blank cells (see screenshot). Is ther a setting I can change to simply get empty cells instead?

AlexG_1-1702927614092.png

 

3 REPLIES 3

jose_gonzalez
Moderator
Moderator

You need to use "emptyValue" when writing you data

df.write.csv(PATH, header=True, emptyValue='')

  Here is a list of APIs references https://spark.apache.org/docs/latest/sql-data-sources-csv.html

AlexG
New Contributor II

Thank you. How would you download to csv the results from a SQL script without the null strings in empty cells?

AlexG_1-1714142384717.png

I mainly work with SQL notebooks

 

 

 

NandiniN
Valued Contributor II
Valued Contributor II

Hi AlexG,

I tested with the table content containing null and with empty data and it works as expected in the download option too.

Here is an eg:

CREATE TABLE my_table_null_test1 (
id INT,
name STRING
);

INSERT INTO my_table_null_test1 (id, name) VALUES
(1, 'John Doe'),
(2, NULL),
(3, 'Jane Doe'),
(NULL, 'Anonymous')
(4, '');
Screenshot 2024-05-01 at 11.31.00.png

If you do not want nulls, you may have to modify the query to use 

coalesce(NULL, '') or
nvl(NULL, '');

 Hope it helps. Thanks!

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.