News for hackers. Stuff that matters.
Re:Problems with Oracle SQL by jwitthuhn on Friday September 10, 2021 @12:38PM (#28483955)
This is missing my favorite oracle quirk: Empty strings are equivalent to null. Trying to insert an empty string into a NOT NULL column will fail, which took me a while to understand the first time I saw it happen.
Re:Problems with Oracle SQL by marcosdumay on Friday September 10, 2021 @01:51PM (#28484963)
> Empty strings are equivalent to null.

No, they are not. Empty strings are completely different from null, and if you go returning them or testing for equality, everything will break by random some single-digit percent of the time. The same for concatenating, taking the length or iterating.

I imagine there's some deterministic procedure to decide what leads to an empty string and what leads to null. The one thing I know is that if you insert it on a table, you will always get null.

Re:Problems with Oracle SQL by tux3 on Friday September 10, 2021 @03:23PM (#28485959)
Fascinating. Of course it would be too easy if they were strictly the same!

It seems like reading the tale of a greek programmer cursed by the gods to work with madness itself.

Re:Problems with Oracle SQL by vbezhenar on Friday September 10, 2021 @12:45PM (#28484067)
One of oracle quirks for me is varchar2. What happened to varchar1? Nobody knows.
Re:Problems with Oracle SQL by tgv on Friday September 10, 2021 @12:47PM (#28484100)
TIMESTAMP WITH LOCAL TIMEZONE. Never again.
Re:Problems with Oracle SQL by beamatronic on Friday September 10, 2021 @12:59PM (#28484310)
Let me guess, did you get hit with more than one 3:00am?
Re:Problems with Oracle SQL by tmd83 on Friday September 10, 2021 @01:07PM (#28484419)
Let's not forget that Oracle DB uses the system timezone as the datatype storage (not sure what other database do to be honest) so unless you were running your DB machine as UTC by default their timestamp storage would be ambiguous for DST shift and that's their default. Why wouldn't they store everything in UTC and use the system timezone for parse/formatting I have no clue.
Re:Problems with Oracle SQL by tracker1 on Friday September 10, 2021 @02:55PM (#28485680)
I've been pushing to run ALL servers as UTC for a few decades now... always store/transmit date+time as UTC as well. If it's mapped to a locale, pair it with that locale... let the client translate to/from local.
Re:Problems with Oracle SQL by SketchySeaBeast on Friday September 10, 2021 @12:57PM (#28484266)
Oh sorry, are you looking to insert 4001 characters in your varchar2? Buckle up kids, things are gonna get rough.
Re:Problems with Oracle SQL by kubanczyk on Friday September 10, 2021 @03:33PM (#28486036)
Or maybe 3999 chars, of which a couple are two-byte. More fun.
Re:Problems with Oracle SQL by gvenzl on Friday September 10, 2021 @06:29PM (#28487615)
Oracle supports up to 32k VARCHARs since 12.1 released back in 2013.

It just needs to be enabled: https://docs.oracle.com/database/121/REFRN/GUID-D424D23B-093...

Re:Problems with Oracle SQL by icedchai on Friday September 10, 2021 @02:16PM (#28485233)
varchar1 was varchar. I should say "is", since varchar is still supported, they just recommend varchar2 since varchar "might change" (probably not...)
Re:Problems with Oracle SQL by marcosdumay on Friday September 10, 2021 @09:27PM (#28488672)
That one actually changed already. If you follow the new recommendations, varchar is as good as varchar2.
Re:Problems with Oracle SQL by icedchai on Saturday September 11, 2021 @07:50PM (#28497213)
Good to know! I haven't had to touch an Oracle database in almost 15 years, but one never knows.
Re:Problems with Oracle SQL by 5e92cb50239222b on Friday September 10, 2021 @12:50PM (#28484149)
So how do you insert an empty string into a NOT NULL column? Please don't tell me that it's not possible.
Re:Problems with Oracle SQL by postalrat on Friday September 10, 2021 @12:57PM (#28484272)
First you accept that null and an empty string are the same thing. Then you insert a null.
Re:Problems with Oracle SQL by adamzochowski on Friday September 10, 2021 @02:54PM (#28485666)
But 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.

Re:Problems with Oracle SQL by spywaregorilla on Friday September 10, 2021 @03:02PM (#28485740)
Somebody hasn't learned how to love big brother yet.
Re:Problems with Oracle SQL by Brian_K_White on Friday September 10, 2021 @03:45PM (#28486134)
It'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.

Re:Problems with Oracle SQL by tux3 on Friday September 10, 2021 @03:19PM (#28485910)
Bad software punishes you for doing things right.
Re:Problems with Oracle SQL by gmfawcett on Friday September 10, 2021 @01:10PM (#28484450)
Either 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.
Re:Problems with Oracle SQL by myohmy on Friday September 10, 2021 @01:40PM (#28484823)
Honestly 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.
Re:Problems with Oracle SQL by MrStonedOne on Friday September 10, 2021 @03:17PM (#28485888)
Empty 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.

Re:Problems with Oracle SQL by jhgb on Friday September 10, 2021 @04:27PM (#28486508)
An 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.
Re:Problems with Oracle SQL by jhgb on Friday September 10, 2021 @01:02PM (#28484351)
Obviously 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.

Re:Problems with Oracle SQL by zzzeek on Friday September 10, 2021 @12:52PM (#28484188)
its...

....

sorry

not possible (can't store empty string in a NULL col either)

for reals

Re:Problems with Oracle SQL by robertlagrant on Friday September 10, 2021 @02:20PM (#28485293)
Just store the string "empty" and hope there are no nihilists who've changed their names to match. Simple!
Re:Problems with Oracle SQL by munk-a on Friday September 10, 2021 @04:16PM (#28486410)
Real 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)

Re:Problems with Oracle SQL by robertlagrant on Sunday September 19, 2021 @01:39PM (#28586243)
ZZZ? EEK!
Re:Problems with Oracle SQL by tracker1 on Friday September 10, 2021 @02:59PM (#28485714)
Use 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.
Re:Problems with Oracle SQL by jhgb on Friday September 10, 2021 @07:23PM (#28487970)
Or just prefix everything so that your string domain doesn't shrink? Then you don't have to worry what your users enter.
Re:Problems with Oracle SQL by GordonS on Friday September 10, 2021 @02:16PM (#28485236)
It was years ago I first came across this, after I'd already spent a lot of time with MySQL and MSSQL, and some time with PostgreSQL and Firebase. But I still remember having a massive WTF moment!