3

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; 
8
  • 3
    What doesn't work? What is the error you get? Commented Oct 26, 2012 at 8:46
  • 1
    Please add to your question: 1) The schema of your table, 2) some exaple data that already is in the table. Commented Oct 26, 2012 at 8:49
  • 1
    are there any n==0 rows? Commented Oct 26, 2012 at 8:59
  • 1
    @mrcalendar your code should work. Show the schema and values to help better. Answer Marcus question Commented Oct 26, 2012 at 9:10
  • 1
    @mrcalendar If schema and data are trivial, please add them to your question. Commented Oct 26, 2012 at 9:17

1 Answer 1

18

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.