Check Constraint : col1 Null if col2 Not Null

Hi everyone,

I can't found how I can do this,
It seems to me, a python script can not do that because it can not return a null value...

Is there a workaround or something that makes it possible?

Thanks

Answers

  • Hi @RomainH,

    You can return DBNull like this to return NULL
    return DBNull

    But I couldn't get a check for a row value of NULL to work.  I tried
    val is None
    val is not None
    val is DBNull
    val is DBNull.Value
    val == DBNull
    val == DBNull.Value
    But couldn't get it to work.

    If I did 
    def main(config):
            if (col2 == "notnull   "):
            return 4
        else:
            return DBNull
        return 0
    Then it would correctly place null or the number 4


    But that required me to know the value of col2 to check against.

    So I'm not sure what might work here, perhaps you have solved that part of it and just returning DBNull will get you there, if so please let us know!

    Kind regards,
    Alex
    Product Support Engineer | Redgate Software

    Have you visited our Help Center?
Sign In or Register to comment.