Re: row_to_json(), NULL values, and AS

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Neil Conway <neil(dot)conway(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org, pgsql-bugs(at)postgresql(dot)org
Subject: Re: row_to_json(), NULL values, and AS
Date: 2018-06-17 17:43:26
Message-ID: 26543.1529257406@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

I wrote:
> So I'm now pretty well convinced that this is a good change and we
> should slip it into v11.

I wrote a test case and was about ready to commit this, when I started
wondering about the behavior for fdresult == FUNCDETAIL_MULTIPLE.
That is, suppose that the notation f(x) matches more than one candidate
function f, and there's also a column named f. The old code would have
chosen the column interpretation, and so would the patch I posted
previously. But I don't really see how we can square that behavior with
documenting that "we prefer the function interpretation for functional
notation". I think you should get a "function is not unique" error in
such a case, not silently picking the column instead. If it's the
column you want, write it like a column.

So the attached updated patch rearranges the error handling logic to
make that happen.

BTW, while trying to make a test case I was reminded that CREATE FUNCTION
tries to prevent this situation from arising:

regression=# create table t1 (f1 int);
CREATE TABLE
regression=# create function f1(t1) returns int as 'select 42' language sql;
ERROR: "f1" is already an attribute of type t1

That's totally non-bulletproof, though, since you can still create the
situation by renaming, or by adding the conflicting column after you
create the function; not to mention Neil's original problem where the
conflicting function is declared to take record or some such.
Furthermore, this behavior itself creates a dump/reload hazard, since
once you've done one of those things pg_dump will produce output that
fails this check.

While I've not done anything about it here, I think we should just
remove that error check. With this patch, functions and columns can
coexist reasonably peacefully, so we shouldn't need bogus hacks that
try to prevent it.

regards, tom lane

Attachment Content-Type Size
better-handling-for-ambiguous-functional-notation-2.patch text/x-diff 12.2 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Michael Paquier 2018-06-18 02:06:42 Re: BUG #15245: pg_stat_all_tables does not include partition master tables
Previous Message David G. Johnston 2018-06-17 15:29:33 Re: BUG #15245: pg_stat_all_tables does not include partition master tables

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Geoghegan 2018-06-17 18:32:17 Re: Removing "Included attributes in B-tree indexes" section from docs
Previous Message Pavel Stehule 2018-06-17 17:29:34 Re: Query Rewrite for Materialized Views (Postgres Extension)