Search code examples
tdengine

how to update specified field to null with update option equals 2 in TDengine database?


by using update = 2 option when creating database, we can update specified field, how should I update this field to null?

taos> create database db update 2;                                                                                                                                                                                                                                                         [5/2934]
Query OK, 0 of 0 row(s) in database (0.008446s)

taos> use db;
Database changed.

taos> create table tb(ts timestamp, c1 int, c2 nchar(20));
Query OK, 0 of 0 row(s) in database (0.024248s)

taos> insert into tb values(now, 1, "beijing");
Query OK, 1 of 1 row(s) in database (0.008139s)

taos> select * from tb;
           ts            |     c1      |               c2               |
=========================================================================
 2022-02-07 14:54:54.189 |           1 | beijing                        |
Query OK, 1 row(s) in set (0.001694s)

taos> insert into tb values("2022-02-07 14:54:54.189", 2, NULL);
Query OK, 1 of 1 row(s) in database (0.000608s)

taos> select * from tb;
           ts            |     c1      |               c2               |
=========================================================================
 2022-02-07 14:54:54.189 |           2 | beijing                        |
Query OK, 1 row(s) in set (0.005644s)


Solution

  • Because update = 2 cannot achieve what you want, you can use update = 1