Re: Cast jsonb to numeric, int, float, bool

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Teodor Sigaev <teodor@sigaev.ru>
Cc: Robert Haas <robertmhaas@gmail.com>, Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>, Aleksander Alekseev <a.alekseev@postgrespro.ru>, David Steele <david@pgmasters.net>, Nikita Glukhov <n.gluhov@postgrespro.ru>, Darafei Praliaskouski <me@komzpa.net>, Anastasia Lubennikova <a.lubennikova@postgrespro.ru>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2018-05-08T15:17:13Z
Lists: pgsql-hackers
I wrote:
> 1) Does this really pass muster from the translatability standpoint?
> I doubt it.

After further thought about that, it seems that what we typically don't
try to translate is SQL-standard type names, that is, error messages
along the line of "blah blah blah type %s" are considered fine.  So
the problem here is that you factorized the error reporting poorly.
I think you want the callers to look like

 	if (!JsonbExtractScalar(&in->root, &v) || v.type != jbvNumeric)
		cannotCastJsonbValue(v.type, "double precision");

where the subroutine contains the whole ereport() call, and its lookup
table entries are e.g.

	gettext_noop("cannot cast jsonb string to type %s")

			regards, tom lane


Commits

  1. Add casts from jsonb