Attached 16th version of the patches:* changed type of new SQL keyword STRING (STRING is used as a function parameter name in Pl/Tcl tests)* removed implicit coercion via I/O from JSON_VALUE (see below)
On 28.06.2018 07:25, Pavel Stehule wrote:
SQL/JSON standard requires handling of cast errors too.
9.40 Casting an SQL/JSON sequence to an SQL type (pages 724-725):
4) If TEMPST is successful completion, then: b) If the length of SEQ is 1 (one), then let I be the SQL/JSON item in SEQ. Case: ... iii) Otherwise, let IDT be the data type of I. Case: 1) If IDT cannot be cast to target type DT according to the Syntax Rules of Subclause 6.13, "<cast specification>", then let TEMPST be data exception — SQL/JSON item cannot be cast to target type. 2) Otherwise, let X be an SQL variable whose value is I. Let V be the value of CAST (X AS DT). If an exception condition is raised by this <cast specification>, then let TEMPST be that exception condition. ...
5) Case: a) If TEMPST is successful completion, then let OUTST be successful completion. b) If ONERROR is ERROR, then let OUTST be TEMPST. c) If ONERROR is NULL, then let V be the SQL null value and let OUTST be successful completion. d) If ONERROR immediately contains DEFAULT, then let VE be the <value expression> immediately contained in ONERROR. Let V be the value of CAST (VE AS DT) Case: i) If an exception condition is raised by this <cast specification>, then let OUTST be that exception condition. ii) Otherwise, let OUTST be successful completion.
In 4.b.iii.1 said that there should be an error if the desired cast does not exist.
In the previous versions of the patches there was implicit coercion via I/O here
instead of error, so I decided to fix it the last version (fix is combined with a
minor refactoring of ExecEvalJsonExpr()).
--
Nikita Glukhov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company