Thomas Lockhart <lockhart@alumni.caltech.edu> writes:
>> COALESCE sql function causes postgres to CRASH!
>> httpd=> SELECT story.title, COALESCE(story.image, mfr.image)
>> httpd-> FROM story, mfr where story.category= mfr.oid;
> The problem is in combining columns from multiple tables in the
> COALESCE result.
I see at least part of the problem: flatten_tlistentry forgets to
recurse into the 'expr' part of a CaseWhen node. There may be some
other contributing bugs in setrefs.c.
There are dozens of routines in the backend that know all about how to
walk a parse tree --- or, in some cases like this one, not quite all
about how to walk a parse tree :-(. I just spent some time yesterday
teaching a couple of other routines about ArrayRef nodes, for example,
and I've seen way too many other bugs of exactly this ilk.
I think it'd be a good idea to try to centralize this knowledge so that
there are fewer places to change to add a new node type. For example,
a routine that wants to examine all the Var nodes in a tree should be
able to look something like this:
if (IsA(node, Var)){ process var node;}else standard_tree_walker(node, myself, ...);
rather than having another copy of a bunch of error-prone boilerplate.
regards, tom lane