postgresql/src/backend
Tom Lane e136a0d8ca Restore json{b}_populate_record{set}'s ability to take type info from AS.
If the record argument is NULL and has no declared type more concrete
than RECORD, we can't extract useful information about the desired
rowtype from it.  In this case, see if we're in FROM with an AS clause,
and if so extract the needed rowtype info from AS.

It worked like this before v11, but commit 37a795a60 removed the
behavior, reasoning that it was undocumented, inefficient, and utterly
not self-consistent.  If you want to take type info from an AS clause,
you should be using the json_to_record() family of functions not the
json_populate_record() family.  Also, it was already the case that
the "populate" functions would fail for a null-valued RECORD input
(with an unfriendly "record type has not been registered" error)
when there wasn't an AS clause at hand, and it wasn't obvious that
that behavior wasn't OK when there was one.  However, it emerges
that some people were depending on this to work, and indeed the
rather off-point error message you got if you left off AS encouraged
slapping on AS without switching to the json_to_record() family.

Hence, put back the fallback behavior of looking for AS.  While at it,
improve the run-time error you get when there's no place to obtain type
info; we can do a lot better than "record type has not been registered".
(We can't, unfortunately, easily improve the parse-time error message
that leads people down this path in the first place.)

While at it, I refactored the code a bit to avoid duplicating the
same logic in several different places.

Per bug #15940 from Jaroslav Sivy.  Back-patch to v11 where the
current coding came in.  (The pre-v11 deficiencies in this area
aren't regressions, so we'll leave those branches alone.)

Patch by me, based on preliminary analysis by Dmitry Dolgov.

Discussion: https://postgr.es/m/15940-2ab76dc58ffb85b6@postgresql.org
2019-08-19 18:01:09 -04:00
..
access Fix inconsistencies and typos in the tree, take 11 2019-08-19 16:21:39 +09:00
bootstrap Fix inconsistencies and typos in the tree 2019-07-16 13:23:53 +09:00
catalog Fix inconsistencies and typos in the tree, take 10 2019-08-13 13:53:41 +09:00
commands Fix inconsistencies and typos in the tree, take 11 2019-08-19 16:21:39 +09:00
executor Fix inconsistencies and typos in the tree, take 11 2019-08-19 16:21:39 +09:00
foreign Update copyright for 2019 2019-01-02 12:44:25 -05:00
jit Avoid macro clash with LLVM 9. 2019-07-29 10:23:55 +12:00
lib Fix inconsistencies in the code 2019-07-08 13:15:09 +09:00
libpq Fix inconsistencies and typos in the tree, take 10 2019-08-13 13:53:41 +09:00
main initdb: Remove obsolete locale handling 2019-08-14 06:51:13 +02:00
nodes Remove fmgr.h includes from headers that don't really need it. 2019-08-16 10:35:31 -07:00
optimizer Remove useless bms_free() calls in build_child_join_rel(). 2019-08-16 14:35:55 +09:00
parser Rationalize use of list_concat + list_copy combinations. 2019-08-12 11:20:18 -04:00
partitioning Don't include utils/array.h from acl.h. 2019-08-16 10:33:30 -07:00
po Translation updates 2019-06-17 15:30:20 +02:00
port Fix inconsistencies and typos in the tree, take 11 2019-08-19 16:21:39 +09:00
postmaster Fix inconsistencies and typos in the tree, take 11 2019-08-19 16:21:39 +09:00
regex Fix inconsistencies and typos in the tree, take 9 2019-08-05 12:14:58 +09:00
replication Fix inconsistencies and typos in the tree, take 11 2019-08-19 16:21:39 +09:00
rewrite Rationalize use of list_concat + list_copy combinations. 2019-08-12 11:20:18 -04:00
snowball Sync our Snowball stemmer dictionaries with current upstream 2019-07-04 13:26:48 +02:00
statistics Fix inconsistencies and typos in the tree, take 11 2019-08-19 16:21:39 +09:00
storage Fix inconsistencies and typos in the tree, take 11 2019-08-19 16:21:39 +09:00
tcop Revert "Add log_statement_sample_rate parameter" 2019-08-04 23:38:27 +02:00
tsearch Fix inconsistencies and typos in the tree, take 11 2019-08-19 16:21:39 +09:00
utils Restore json{b}_populate_record{set}'s ability to take type info from AS. 2019-08-19 18:01:09 -04:00
.gitignore
Makefile Get rid of jsonpath_gram.h and jsonpath_scanner.h 2019-03-20 11:13:34 +03:00
common.mk Remove PARTIAL_LINKING build mode. 2018-03-30 17:33:04 -07:00
nls.mk Translation updates 2019-05-20 16:00:53 +02:00