Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to assign null to a field in sqlite

Tags:

sql

sqlite

I would like to assign null to a field in SQLite but am not getting anywhere with this:

update t set n=null where n=0;
like image 336
mr calendar Avatar asked Jan 24 '26 18:01

mr calendar


1 Answers

I can not reproduce your problem. From what you write, I guess your table looks like this:

CREATE TABLE t (n integer);

Inserting data:

insert into t values (1);
insert into t values (2);
insert into t values (3);
insert into t values (0);

Updating the data with your UPDATE:

update t set n = null where n = 0;

Now the table looks like this:

sqlite> .dump
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE t (n integer);
INSERT INTO "t" VALUES(1);
INSERT INTO "t" VALUES(2);
INSERT INTO "t" VALUES(3);
INSERT INTO "t" VALUES(NULL);
COMMIT;

There might be no output after the UPDATE but it has the desired effect.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!