Fiss column value (= null) depending on the value of another column



  • Table tablename There are columns. type and arg♪ We need to put in a restriction on which type = 1Always. arg = null

    How can this be organized in PostgreSQL? Version 9.5.2.

    This can be achieved at the annex level, but it is required at the CBD level. So she wouldn't let her break this rule.



  • ALTER TABLE test 
    ADD CONSTRAINT null_arg 
    CHECK ((type = 1 AND arg IS NULL) OR type <> 1)
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2