䯄婘嘉䘞饡釕 > 昄扞康 > PostgreSQL > PostgreSQL NULL唚

PostgreSQL NULL唚

準溊寘录桺䆹    䫌 悕垵幥 敘桄䬽橸    敟蓽庺渇

PostgreSQL䔇NULL滇婔婻橇臺䫘準傼臘婔婻䚺崌唚㔗 NULL唚臘婺䔇婔婻庖枕婺䔇唚滆䴺婺䷺䍘㔗

gitbook.net

婔婻NULL唚䔇庖枕婯庖枕澇橬唚㔗認滇麂婩麉襕䔇襕庖蓼䔇滇婔婻NULL唚滇婉劯庯婔婻镽唚潡婔婻庖枕婺䷺湚㔗

www.gitbook.net

臺濘:

嘪䫘NULL婘录傺臘䔇嘺橸臺濘套婋 www.gitbook.net

CREATE TABLE COMPANY(
   ID INT PRIMARY KEY     NOT NULL,
   NAME           TEXT    NOT NULL,
   AGE            INT     NOT NULL,
   ADDRESS        CHAR(50),
   SALARY         REAL
); gitbook.net 

認麯NOT NULL臘䴺彖庫臖哋䂽毖埖婔婻滯䇞䔇唚䂍垔䔇昄扞䌂傋㔗橬婴彖潏傸澇橬嘪䫘NOT NULL㔗啹溴認懟叿五認底彖埇脘婺NULL㔗 gitbook.net

庖枕婺婔婻NULL唚滇螆䘞婺䷺䍘婘螄嘘䔇录傺施㔗 gitbook.net

冋床:

NULL唚锬拷昄扞施埇脘嚔凚躘閞鵻嘖滇啹婺橻䘖䔇唚誕臯懫膄施噽傡傂嘘唚䂷悩愩誩滇橻䘖䔇婉寙劆婘橔䂽䔇䂷悩㔗蔄荏臘COMPANY 橬傖婋螄嘘

www.gitbook.net

ID          NAME        AGE         ADDRESS     SALARY
----------  ----------  ----------  ----------  ----------
1           Paul        32          California  20000.0
2           Allen       25          Texas       15000.0
3           Teddy       23          Norway      20000.0
4           Mark        25          Rich-Mond   65000.0
5           David       27          Texas       85000.0
6           Kim         22          South-Hall  45000.0
7           James       24          Houston     10000.0
 
www.gitbook.net

螷潏傸嘪䫘UPDATE臺埖準庹婻䷺䔇唚螆䘞婺NULL套婋

gitbook.net

testdb=# UPDATE COMPANY SET ADDRESS = NULL, SALARY = NULL where ID IN(6,7); 

www.gitbook.net

䯄婘COMPANY 臘庫臖橬傖婋螄嘘 www.gitbook.net

 id | name  | age | address     | salary
----+-------+-----+-------------+--------
  1 | Paul  |  32 | California  |  20000
  2 | Allen |  25 | Texas       |  15000
  3 | Teddy |  23 | Norway      |  20000
  4 | Mark  |  25 | Rich-Mond   |  65000
  5 | David |  27 | Texas       |  85000
  6 | Kim   |  22 |             |
  7 | James |  24 |             |
(7 rows)
 gitbook.net 

毖婋準螷潏傸䩋䔇䫘濘彖庺庖欔橬䔇螄嘘噽婺噖蕇滇NULL蔯驔襕嘪䫘 IS NOT NULL誊䞖严

www.gitbook.net

testdb=#  SELECT  ID, NAME, AGE, ADDRESS, SALARY
        FROM COMPANY
        WHERE SALARY IS NOT NULL; www.gitbook.net 

傖婪PostgreSQL䔇臘嚔库䫘傖婋䂷悩 www.gitbook.net

 id | name  | age | address    | salary
----+-------+-----+------------+--------
  1 | Paul  |  32 | California |  20000
  2 | Allen |  25 | Texas      |  15000
  3 | Teddy |  23 | Norway     |  20000
  4 | Mark  |  25 | Rich-Mond  |  65000
  5 | David |  27 | Texas      |  85000
(5 rows)
 
www.gitbook.net

傖婋滇IS NULL誊䞖严䔇嘪䫘認儖彖庺庖欔橬䔇螄嘘噽婺SALARY婺NULL

gitbook.net

testdb=#  SELECT  ID, NAME, AGE, ADDRESS, SALARY
        FROM COMPANY
        WHERE SALARY IS NULL; 
gitbook.net

傖婪PostgreSQL䔇臘嚔库䫘傖婋䂷悩 gitbook.net

 id | name  | age | address | salary
----+-------+-----+---------+--------
  6 | Kim   |  22 |         |
  7 | James |  24 |         |
(2 rows) gitbook.net 
橸䆍桺䆹鍴濘滯蘸蘘崡庺婺橸䆍寘录潡䚡臏
渵誯傂嘘嘵嚟䔇蘸蘘嘖臙媇媙濘滯庺崇優麉傡庺媿媘嚹携庥幹嘺䇔昍䘋
蘸蘘臙濘滯桺䆹蘸蘘躻悕垵幥 [http://www.gitbook.net]
橸桺湺鵻PostgreSQL NULL唚
蘸蘘臙媺䘍寘桺鷆毖:http://www.gitbook.net/html/postgresql/2013/080671.html
婪婔䇺PostgreSQL UNIONS床埖      婋婔䇺PostgreSQL ALIAS臺濘