Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android SQLite fts3: What should I insert: null values OR empty strings?

I've created a SQLite FTS3 table for an Android app with several columns. The table is populated by user's inputs. However not all table columns should have a value. Example: There is a column named PLURAL. The user submits a word which is a verb (not a noun) and so the PLURAL column shouldn't have a value.

What should I input into the PLURAL column, a NULL value or an empty string ""?

Except for the logic that affects the answer, is there any significant difference in the Database performance if I use NULL over empty string values? Are there any known issues (e.g. throw exceptions) if I use NULL values?

I 've searched around the web and I 've found some opinions on other DB but not on SQLite fts3.

Thank you!

like image 823
kkats Avatar asked Sep 05 '14 12:09

kkats


People also ask

Should I use empty string or NULL?

An empty string is useful when the data comes from multiple resources. NULL is used when some fields are optional, and the data is unknown.

Is NULL or empty in SQLite?

SQLite IS NOT NULL operator This picture illustrates the partial output: In this tutorial, you have learned how to check if values in a column or an expression is NULL or not by using the IS NULL and IS NOT NULL operators. Was this tutorial helpful ?

How does SQLite handle NULL values?

Syntax. Following is the basic syntax of using NULL while creating a table. SQLite> CREATE TABLE COMPANY( ID INT PRIMARY KEY NOT NULL, NAME TEXT NOT NULL, AGE INT NOT NULL, ADDRESS CHAR(50), SALARY REAL ); Here, NOT NULL signifies that the column should always accept an explicit value of the given data type.

Can we insert empty string in NOT NULL column?

Yes you can...


2 Answers

Based on logic: you should not insert empty string but NULL, since in SQL word NULL is treated as NO VALUE

There's no preformance issues related to emptyness or nulliness of string. The only consideration can emerge in case of SQL inner join statement. INNER JOIN joins only non NULL fields which fits to join conditions. There's special LEFT/RIGHT JOIN statements which permits usage of NULL fields in joins.

like image 143
Barmaley Avatar answered Sep 27 '22 20:09

Barmaley


what i understood after going through multiple posts is that it handles null as combination of behavior from different database engines.

The goal is to make SQLite handle NULLs in a standards-compliant way. But the descriptions in the SQL standards on how to handle NULLs seem ambiguous. It is not clear from the standards documents exactly how NULLs should be handled in all circumstances.

refer this for detailed information http://www.sqlite.org/nulls.html

like image 33
karan Avatar answered Sep 27 '22 18:09

karan