"select" is a workhorse, "update" is as routine as a pair of pants. "coalesce" is something special

Mar 19, 2009 18:37

An Ode To Coalesce

Coalesce
I must confess
You're my favourite database function

Coalesce
With such finesse
You return the first non-null value in the argument list

Coalesce
You do impress
With the lovely name you've chosen

Coalesce
When I assess
All the other database functions you're always among my favourites

Leave a comment

Comments 31

ultrastefan March 19 2009, 22:58:54 UTC
At first I thought this was an ode to Coalesce the band. Alas not.

Reply

scarfboys March 20 2009, 02:09:40 UTC
I suppose the third could be.

Reply

nunzio March 25 2009, 17:19:41 UTC
i too made this mistake.
i was wicked stoked.

Reply


_fluffy March 19 2009, 23:01:48 UTC
So what good is it in real use, anyway? I'd never seen it come up before today, when suddenly one of our customers said, "Oh yeah we might need to use coalesce in [SQL-esque database engine], will that be possible?" and I'm thinking, "Okay, what the hell do you need this for, and why did you wait until now to say you might want it?"

They're also begging for us to allow inline parameters instead of bound parameters, too. Screw the security concerns and massive bloat that would add to the expression parser!

Reply

qwantz March 19 2009, 23:11:20 UTC
It's so useful! There's situations in which you might have one optional, more-detailed field, and a default field, so you could use coalesce(maybeitsthere, definitelythere). Or you could have an option field, so you could use coalesce(optionalfield, 'somedefaultvalue'). Or you could have a calculation which might return null, and using this you can trap that and stop it from spreading outword by subbing in 0!

It's invaluable in very specific situations. I was wishing for such a function and got partway into coding it before I discovered coalesce years ago, and it has been tru luv ever since.

Reply

_fluffy March 19 2009, 23:20:36 UTC
Oh, I see, so like,

SELECT COALESCE(this,that,theother) FROM foo;

as opposed to SELECT this,that,theother FROM foo; and having the client have to do dumb fallback. But that doesn't help if the app also needs to know which column gave the data (which is the case for this app).

I can see how it might be useful in some contexts but I really can't see its value for our clients, so. I think it's more like they're asking for a complete SQL implementation "just in case they need it" when in the context of this system there's no reason they could even pretend to expect that (this is on an embedded system, to start with). Gah.

Reply

thestormsurfer March 24 2009, 18:53:30 UTC
"invaluable", which does not mean the opposite of "valuable". What a language!

Reply


_fluffy March 19 2009, 23:02:59 UTC
Also completely apropos to nothing but will you ever fix the OhNoRobot XML export to actually emit the separate panels? I've raised this both on the ONR forum and by email and you are usually good about replying to things but on this one thing you have been surprisingly quiet and for some reason it just crossed my mind to ask you again.

Reply

qwantz March 19 2009, 23:09:17 UTC
I guess I haven't! Send me another email with the details and I'll try to get to it this month.

Reply

_fluffy March 19 2009, 23:25:47 UTC
Not really much detail to give! Just that every comic gets all the panels' lines in a single
tag rather than each panel separated out like it's supposed to be, so there's no way for XML consumers to know where the panels begin and end.

I had emailed it to the ohnorobot contact email address instead of your qwantz one so maybe that is why you never saw it?

Anyway I will forward the message to your qwantz address (goodness, I sent it back in December).

Reply


professor March 19 2009, 23:06:49 UTC
Coalesce is misspelled: Currently the title says "An Ode To Coalese."

Reply

qwantz March 19 2009, 23:08:58 UTC
Thanks!

Reply

professor March 19 2009, 23:13:10 UTC
Just doing my editorial duty.

Reply


stegosaurus_rex March 19 2009, 23:41:38 UTC
Also "favourite" is less correctly spelled than it should be.

Love,
An American.

Reply

boxer_the_horse March 20 2009, 06:20:12 UTC
Exactly. It should be spelled F-A-V-Oh! You ruined everyone's economy! Great Job!-R-I-T-E.

Reply

stegosaurus_rex March 20 2009, 11:08:00 UTC
Ha!

Reply

thestormsurfer March 24 2009, 18:50:46 UTC
No, it was me. I ruined everyone's economy.

Reply


Leave a comment

Up