summaryrefslogtreecommitdiff
path: root/doc/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2018-06-18 11:39:33 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2018-06-18 11:39:33 -0400
commitb97a3465d73bfc2a9f5bcf5def1983dbaa0a26f8 (patch)
tree729c396a8314c6db5219beeb8c385b11a5646f60 /doc/src
parent4c8156d87108fa1f245bee13775e76819cd46a90 (diff)
Consider syntactic form when disambiguating function vs column reference.
Postgres has traditionally considered the syntactic forms f(x) and x.f to be equivalent, allowing tricks such as writing a function and then using it as though it were a computed-on-demand column. However, our behavior when both interpretations are feasible left something to be desired: we always chose the column interpretation. This could lead to very surprising results, as in a recent bug report from Neil Conway. It also created a dump-and-reload hazard, since what was a function call in a dumped view could get interpreted as a column reference at reload, if a matching column name had been added to the underlying table since the view was created. What seems better, in ambiguous situations, is to prefer the choice matching the syntactic form of the reference. This seems much less astonishing in general, and it fixes the dump/reload hazard. Although this could be called a bug fix, there have been few complaints and there's some small risk of breaking applications that depend on the old behavior, so no back-patch. It does seem reasonable to slip it into v11, though. Discussion: https://postgr.es/m/CAOW5sYa3Wp7KozCuzjOdw6PiOYPi6D=VvRybtH2S=2C0SVmRmA@mail.gmail.com
Diffstat (limited to 'doc/src')
-rw-r--r--doc/src/sgml/rowtypes.sgml9
1 files changed, 6 insertions, 3 deletions
diff --git a/doc/src/sgml/rowtypes.sgml b/doc/src/sgml/rowtypes.sgml
index 3f24293175d..2f924b1f85d 100644
--- a/doc/src/sgml/rowtypes.sgml
+++ b/doc/src/sgml/rowtypes.sgml
@@ -441,9 +441,12 @@ SELECT c.somefunc FROM inventory_item c;
Because of this behavior, it's unwise to give a function that takes a
single composite-type argument the same name as any of the fields of
that composite type. If there is ambiguity, the field-name
- interpretation will be preferred, so that such a function could not be
- called without tricks. One way to force the function interpretation is
- to schema-qualify the function name, that is, write
+ interpretation will be chosen if field-name syntax is used, while the
+ function will be chosen if function-call syntax is used. However,
+ <productname>PostgreSQL</productname> versions before 11 always chose the
+ field-name interpretation, unless the syntax of the call required it to
+ be a function call. One way to force the function interpretation in
+ older versions is to schema-qualify the function name, that is, write
<literal><replaceable>schema</replaceable>.<replaceable>func</replaceable>(<replaceable>compositevalue</replaceable>)</literal>.
</para>
</tip>