4 ms·
So how do you insert an empty string into a NOT NULL column? Please don't tell me that it's not possible.
by 5e92cb50239222b 5y ago
So how do you insert an empty string into a NOT NULL column? Please don't tell me that it's not possible.
- zzzeek 5y agoits... .... sorry not possible (can't store empty string in a NULL col either) for reals
- robertlagrant 5y agoJust store the string "empty" and hope there are no nihilists who've changed their names to match. Simple!
- tracker1 5y agoUse vertical tab, or another whitespace or field separator character, like EOF etc. Generally something a modern keyboard won't be entering, and won't generally be transmitted over the wire.
- jhgb 5y agoOr just prefix everything so that your string domain doesn't shrink? Then you don't have to worry what your users enter.
- munk-a 5y agoReal programmers encode emptiness as ZZZ... (I once worked maintaining a MUD that used internal memory management and marked block terminals (which were unnecessary since it stored the length of blocks it had allocated) with ZZZ)
- robertlagrant 5y agoZZZ? EEK!
- postalrat 5y agoFirst you accept that null and an empty string are the same thing. Then you insert a null.
- adamzochowski 5y agoBut they are not. Empty string means "we know this is empty", Null means "We don't know". For example, I have a second name. Some people don't have second names. And some records we might not even know if such exists. Null means "unknown". Empty string cannot be equal to null.
- spywaregorilla 5y agoSomebody hasn't learned how to love big brother yet.
- tux3 5y agoBad software punishes you for doing things right.
- Brian_K_White 5y agoIt's like how at one time, "0" was not yet invented and had to be invented and explained, and it was a revolution for math. It's a quantity just like 5 or 244, but for when the amount happens to be none. We need that again, another new 0 concept to add to 0, to distinguish between "set-to-0" and "not-yet-set". Maybe 2 new concepts, since null is also different from 0. 0 is a value, null is the absense of a value. Not just as an idiom or implementation detail in a programming language, but as a general concept that may be used anywhere in life. Without it, we have exactly these confusions and ambiguities and differences of opinion about how to do something or what something means or what something should mean.
- jhgb 5y agoObviously you prefix every string with a space and when reading, strip the leading space. Then " " is your empty string. ;) For real though, no idea. I'm glad that I never had to touch Oracle.
- gmfawcett 5y agoEither make the column nullable, or apply local workarounds and folklore. E.g. I've seen "person" records with surname = '.' in certain databases, for people who don't have one.
- myohmy 5y agoHonestly that's bad db design anyways. If empty string is a valid value then you don't want NOT NULL anyways. This is a table structure constraint, not a variable declaration. NOT EMPTY would have been a better syntax imo but that's a whole can of worms.
- MrStonedOne 5y agoEmpty string means "we know its blank" null means "we don't know". When it comes to datatyping, (the whole point of data types in a db), null is its own datatype, so forcing the allowance of nulls to get blank strings is kinda stupid and only causes software/application level bugs.
- jhgb 5y agoAn empty string is a perfectly valid neutral element of the free monoid over the alphabet in question. It's also not a NULL value for this reason. If a NOT NULL column of strings allows for all strings except for a very important one, then that's a very weirdly special-cased design of the RDBMS.