/*
$CONN4 --file=/home/jian/scratch/scratchpads/47a6066b9dfaca1c2b13ea2e99f4e929/scratch169.sql
{bpcharin,varcharin,time_in,timestamp_in,timestamptz_in,interval_in,timetz_in,bit_in,varbit_in,numeric_in}
time_in:        AdjustTimeForTypmod(&result, typmod);
timestamp_in:   AdjustTimestampForTypmod
timestamptz_in:	AdjustTimestampForTypmod(&result, typmod, escontext);
interval_in:    AdjustIntervalForTypmod(result, typmod, escontext);
timetz_in:      AdjustTimeForTypmod(&(result->time), typmod);
numeric_in:     apply_typmod(NumericVar *var, int32 typmod, Node *escontext)
varbit_in:
                ereturn(escontext, (Datum) 0,
                        (errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION),
                        errmsg("bit string too long for type bit varying(%d)",
                                atttypmod)));
varbit_in same as bit_in.
*/
SELECT JSON_VALUE(jsonb '1234', '$' RETURNING bit(3)  DEFAULT 010111 ON ERROR);


CREATE DOMAIN queryfuncs_char2 AS char(2) CHECK (VALUE NOT IN ('12'));
CREATE DOMAIN queryfuncs_d_interval AS interval(2) CHECK (VALUE is not null);
CREATE DOMAIN queryfuncs_d_numeric AS numeric(5,2) CHECK (VALUE is not null);
CREATE DOMAIN queryfuncs_d_bit2 AS bit(2) CHECK (VALUE is not null);
CREATE DOMAIN queryfuncs_d_varbit3 AS varbit(3) CHECK (VALUE is not null);
SELECT JSON_VALUE(jsonb '123', '$' RETURNING queryfuncs_char2 DEFAULT 13 ON ERROR);
SELECT JSON_VALUE(jsonb '123', '$' RETURNING queryfuncs_char2 DEFAULT '13' ON ERROR);
SELECT JSON_VALUE(jsonb '123', '$' RETURNING queryfuncs_char2 DEFAULT '134' ON ERROR);
SELECT JSON_VALUE(jsonb '"01:23:15.6789"', '$'  RETURNING queryfuncs_d_interval default '01:23:45.167891' on error);
SELECT JSON_VALUE(jsonb '"01:23:15.6789"', '$'  RETURNING interval(2) default '01:23:45.167891' on error);
SELECT JSON_VALUE(jsonb '21111.1341', '$' RETURNING queryfuncs_d_numeric  DEFAULT '12.134' ON ERROR);
SELECT JSON_VALUE(jsonb '21111.1341', '$' RETURNING queryfuncs_d_numeric  DEFAULT 11111112.134 ON ERROR);

SELECT JSON_VALUE(jsonb '12', '$' RETURNING queryfuncs_d_bit2  DEFAULT 11 ON ERROR);
SELECT JSON_VALUE(jsonb '"111"', '$'  RETURNING bit(2) error on error);
SELECT JSON_VALUE(jsonb '"111"', '$'  RETURNING queryfuncs_d_bit2 error on error);
SELECT JSON_VALUE(jsonb '"111"', '$'  RETURNING queryfuncs_d_bit2 default '1' on error);
SELECT JSON_VALUE(jsonb '"111"', '$'  RETURNING queryfuncs_d_bit2 default '01' on error);
SELECT JSON_VALUE(jsonb '"111"', '$'  RETURNING queryfuncs_d_bit2 default '111' on error);
SELECT JSON_VALUE(jsonb '"111"', '$'  RETURNING bit(3) default '1111' on error);
SELECT JSON_VALUE(jsonb '1234', '$' RETURNING bit(3)  DEFAULT 1::int8 ON ERROR);
SELECT JSON_VALUE(jsonb '1234', '$' RETURNING bit(3)  DEFAULT 010111 ON ERROR);
SELECT JSON_VALUE(jsonb '1234', '$' RETURNING bit(3)  DEFAULT 32 ON ERROR);
SELECT JSON_VALUE(jsonb '1234', '$' RETURNING queryfuncs_d_varbit3  DEFAULT 111111 ON ERROR);
SELECT JSON_VALUE(jsonb '1234', '$' RETURNING queryfuncs_d_varbit3  DEFAULT '111111' ON ERROR);
SELECT JSON_VALUE(jsonb '1234', '$' RETURNING varbit(3)  DEFAULT '111111' ON ERROR);
SELECT JSON_VALUE(jsonb '1234', '$' RETURNING varbit(3)  DEFAULT '000' ON ERROR);
SELECT JSON_VALUE(jsonb '1234', '$' RETURNING varbit(3)  DEFAULT 11 ON ERROR);
SELECT JSON_VALUE(jsonb '1234', '$' RETURNING queryfuncs_d_varbit3  DEFAULT '01' ON ERROR);