Clarification for use of null and conditions in INSERT and UPDATE Queries

I am looking for clarification on the use of conditions and .default(null) in both the Value and Condition in Insert and Update Queries.

Below I have set out a table with examples of 'text', 'number' and 'date' fields. Each of these has six combination examples of how they could be used. I suppose I am looking for clarification on which should be used and which should not. And in the case of which should be used, then why would you use it.

Also, the answer may well depend on the database, whether it has any form of Strict applied, and whether NULL values are allowed. If your answers include any of this further information I am sure people would find it helpful.

I know this could be expanded with formatting in the Value column or, say max() in the Condition column but I am trying to get the basics right.

┌────┬──────────────┬──────┬───────────────────────────────────────┬───────────────────────────────────────┐
│ #  │    Column    │ Type │                 Value                 │               Condition               │
├────┼──────────────┼──────┼───────────────────────────────────────┼───────────────────────────────────────┤
│  1 │ trading_name │ text │ {{$_POST.trading_name}}               │                                       │
│  2 │ trading_name │ text │ {{$_POST.trading_name.default(null)}} │                                       │
│  3 │ trading_name │ text │ {{$_POST.trading_name}}               │ {{$_POST.trading_name}}               │
│  4 │ trading_name │ text │ {{$_POST.trading_name.default(null)}} │ {{$_POST.trading_name}}               │
│  5 │ trading_name │ text │ {{$_POST.trading_name}}               │ {{$_POST.trading_name.default(null)}} │
│  6 │ trading_name │ text │ {{$_POST.trading_name.default(null)}} │ {{$_POST.trading_name.default(null)}} │
├────┼──────────────┼──────┼───────────────────────────────────────┼───────────────────────────────────────┤
│  7 │ ref_num      │ num  │ {{$_POST.ref_num}}                    │                                       │
│  8 │ ref_num      │ num  │ {{$_POST.ref_num.default(null)}}      │                                       │
│  9 │ ref_num      │ num  │ {{$_POST.ref_num}}                    │ {{$_POST.ref_num}}                    │
│ 10 │ ref_num      │ num  │ {{$_POST.ref_num.default(null)}}      │ {{$_POST.ref_num}}                    │
│ 11 │ ref_num      │ num  │ {{$_POST.ref_num}}                    │ {{$_POST.ref_num.default(null)}}      │
│ 12 │ ref_num      │ num  │ {{$_POST.ref_num.default(null)}}      │ {{$_POST.ref_num.default(null)}}      │
├────┼──────────────┼──────┼───────────────────────────────────────┼───────────────────────────────────────┤
│ 13 │ post_date    │ date │ {{$_POST.post_date}}                  │                                       │
│ 14 │ post_date    │ date │ {{$_POST.post_date.default(null)}}    │                                       │
│ 15 │ post_date    │ date │ {{$_POST.post_date}}                  │ {{$_POST.post_date}}                  │
│ 16 │ post_date    │ date │ {{$_POST.post_date.default(null)}}    │ {{$_POST.post_date}}                  │
│ 17 │ post_date    │ date │ {{$_POST.post_date}}                  │ {{$_POST.post_date.default(null)}}    │
│ 18 │ post_date    │ date │ {{$_POST.post_date.default(null)}}    │ {{$_POST.post_date.default(null)}}    │
└────┴──────────────┴──────┴───────────────────────────────────────┴───────────────────────────────────────┘

I seem to have got myself into a muddle with various combinations and would like it sorting once and for all. Cheers

Community Page
Last updated: