Tuesday, December 01, 2026

Longevity drugs

There was a very interesting item in last night's news programme about longevity drugs. It started by showing reseach being carried out in Bar Ilan university about the SERT-6 gene/protein; according to the professor being interviewed, injecting this into mice caused an increase of 30% of their life span. The intention of this research is to produce an injectable drug for humans. From there, the item discussed the apparent longevity-extending properties of drugs such as metformin, the first line treatment for type 2 diabetes, and the GLP-1 agonists such as semaglutide (aka wegovy). I didn't know that this drug can also be used to treat diabetes, being prescribed when metformin is not tolerated. There was no mention of quality of life: it's all very well extending someone's life, but if they are bed-ridden then it's not much of a bargain.

This reminded me of a Robert Silverberg novella from the mid-1970s, "Going", that begins "In the early spring of 2095, with his one hundred thirty sixth birthday coming on, Henry Staunt decided quite abruptly that the moment had arrived for him to Go". I haven't read this story in 40 years and I don't appear to have an e-book version, so I shall have to read the story from the paperback that I purchased over 50 years ago. As one can appreciate from that opening sentence, people live twice as long as they do now with full quality of life. The story 'contemplates the mysteries of state aided suicide', to quote the book's back cover.

What the news item - and Silverberg - ignored is the financial effect of living much longer. At what age will people retire, 80? 90? 100? A recent retiree myself, the thought of going back to full time work for another ten or twenty years is not appealing. The National Insurance doesn't have enough money to pay old age pensions for those who receive them now, and extending longevity will mean that there will be more retirees than working people and so there definitely won't be enough money for OA pensions. The same holds for pension funds into which employees and employers pay money each month so that a retiree will receive a generous pension upon retiring. I'm not going to discuss Israeli pension funds but some of them might have liquidity problems now. The entire 'saving for pension' programme would have to be rethought.

So, would I want to live to 100? Possibly, but I would definitely require that my quality of life remain.



This day in blog history:

Blog #Date TitleTags
11101/12/2007SleepApnea, Anaemia
65401/12/2013Critical weekDBA
77901/12/2014My army service - part oneIsrael, Army service
136101/12/2020E-hour minus 4DBA
136201/12/2020Viva resultDBA
144401/12/2021My body is like a barometerWeather
155801/12/2022Christine McVie, RIPObituary, Fleetwood Mac
169101/12/2023Restringing the Stagg - againGuitars
186801/12/2024Armand Gamache - a new (to me) detective series Kobo, Louise Penny

Monday, November 30, 2026

I should use the coalesce function more often

To give the dictionary definition,  The COALESCE function in SQL evaluates a list of arguments from left to right and returns the first non-NULL value. If every argument evaluates to NULL, it returns NULL. 

When would one use this function? I'll give a few examples from the OP's "ERP" program. The USERS table has both a name field and a nickname field. The latter field is very useful, for the first holds a computer's name. In the case of the computer on which I'm writing this, the computer's name is DESKTOP-VJ4782Q which is not very helpful. On the other hand, the tuple with that value has "No'am" as the nickname, which is much more helpful. Not all tuples in the USERS table has a nickname, though. In the past, I have written clauses such as

select case when users.nickname = '' then users.name else users.nickname end as aname

This is a very wordy method. I could also have written this as when users.nickname <> '' and reversed the order (i.e. 'nickname' would come before 'name'. It would, however, been more simple to use the COALESCE function in place of a case statement: select coalesce (users.nickname, users.name) as aname. Here, 'nickname' has to come first: if it's not null then it will be selected, otherwise 'name' - which is guaranteed to not be null - will be selected.

This is the simple case (pun not intended) where both values come from the same table, but it doesn't have to be so. I don't have many examples in ERP program of queries where a field value could come from more than one table, but in fact, my initial version of the complicated query1 from a few days ago displayed this property. As I wrote there, the initial version contained the following

case when cc.sug = 'C' then c.cname when cc.sug = 'T' then t.name when cc.sug = 'A' then c_a.cname else '' end as contactname

But as CoPilot pointed out, there was no need for a 'case' statement as for a given row, only one of those fields will have a value, and so the clause could be written more concisely as coalesce (c.cname, t.name, c_a.cname) as contactname,. I had to add another field to the query this morning - either the contact's id, the therapist's id or the customer contact's id. As again only one field will have a value, I could write this simply as coalesce (c.id, t.id, contacts2cust.id) as id.

I've gone through the program and replaced 'case' statements with 'coalesce' wherever possible. I should use this function more often. I wonder whether it exists in the Priority subset of SQL (there are often statements similar to the 'nickname <> '' ? nickname : name idiom) but presumably not, for otherwise these statements would be written with 'coalesce'.

Is there any difference in execution between these two alternative constructs? Apparently there is virtually no performance difference between COALESCE and a CASE statement because most SQL engines internally rewrite COALESCE as a CASE expression. However, choosing one over the other makes a noticeable difference in readability, flexibility, and subquery evaluation.

Internal links
[1] 2172



This day in blog history:

Blog #Date TitleTags
14830/11/2008Criminal JusticeTV series
65330/11/2013Arik EinsteinIsrael, Obituary
98830/11/2016Backing up dataComputers
155730/11/2022Mid-night revelationsDBA