Cheat Sheet

Tuesday, January 10, 2017

psql: INSERT, if already exists, SELECT (two cidr version)

It is actually quite weird. I already set that the cidr is not null, but still, i can happily insert null value inside that.

Hence, it come the problem. I can't select if one of the column's value is null. COALESCE didn't help (on its own). Now we have to modify our script a little bit.

One of the solution is setting default value for cidr-typed column. But what value? 0.0.0.0/0 obviously didn't help. Because null is null. 0.0.0.0/0 is everyone.

Now here what i do.

Let say, we have



Hence, the (unoptimized, but working) query is like this:

*change 192.168.43.199 to Address Client and 0.0.0.0 to X Forwarded For Address, both nullable



tadah

No comments:

Post a Comment