1

Currently, Python is storing the string "None" for nulls returned by sqlite3. I read that you can change the default value for nulls in sqlite3 at the command line, but can you set this within the Python code?

I'd like all of my blank results to look the same without having to loop through and check each value. So I want any nulls returned from sqlite3 to be an empty string ("") instead of "None".

2 Answers 2

1

Uses the SQL-Function COALESCE for each column of your left join.

SELECT 
  a.id, a.value, 
  COALESCE(b.id, ''), COALESCE(b.value, '')
FROM 
  a 
  LEFT OUTER JOIN b ON b.a_id = a.id 
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! This solution works perfectly for what I was doing at the time where I only had one or columns to worry about. I would still like to find a way to do it programmatically so I wouldn't have to build the coalesce function into every sql statement that might produce these results.
0

In docs there is an explanation with examples of how to make use of converters and adapters.

1 Comment

Yes, I read that section, but unless I'm missing something, it does not help in this situation. I don't have one specific column that I'm selecting that has nulls, nor a specific data type that is coming back null, almost any column can come back with nulls using a left join.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.