Convert a few more datatype input functions to report errors softly.

Convert bit_in, varbit_in, inet_in, cidr_in, macaddr_in, and
macaddr8_in to the new style.

Amul Sul, minor mods by me

Discussion: https://postgr.es/m/CAAJ_b97KeDWUdpTKGOaFYPv0OicjOu6EW+QYWj-Ywrgj_aEy1g@mail.gmail.com
This commit is contained in:
Tom Lane 2022-12-14 13:22:08 -05:00
parent b18c2decd7
commit 17407a8eaa
12 changed files with 230 additions and 56 deletions

View File

@ -55,6 +55,7 @@ Datum
macaddr_in(PG_FUNCTION_ARGS) macaddr_in(PG_FUNCTION_ARGS)
{ {
char *str = PG_GETARG_CSTRING(0); char *str = PG_GETARG_CSTRING(0);
Node *escontext = fcinfo->context;
macaddr *result; macaddr *result;
int a, int a,
b, b,
@ -88,7 +89,7 @@ macaddr_in(PG_FUNCTION_ARGS)
count = sscanf(str, "%2x%2x%2x%2x%2x%2x%1s", count = sscanf(str, "%2x%2x%2x%2x%2x%2x%1s",
&a, &b, &c, &d, &e, &f, junk); &a, &b, &c, &d, &e, &f, junk);
if (count != 6) if (count != 6)
ereport(ERROR, ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for type %s: \"%s\"", "macaddr", errmsg("invalid input syntax for type %s: \"%s\"", "macaddr",
str))); str)));
@ -96,7 +97,7 @@ macaddr_in(PG_FUNCTION_ARGS)
if ((a < 0) || (a > 255) || (b < 0) || (b > 255) || if ((a < 0) || (a > 255) || (b < 0) || (b > 255) ||
(c < 0) || (c > 255) || (d < 0) || (d > 255) || (c < 0) || (c > 255) || (d < 0) || (d > 255) ||
(e < 0) || (e > 255) || (f < 0) || (f > 255)) (e < 0) || (e > 255) || (f < 0) || (f > 255))
ereport(ERROR, ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("invalid octet value in \"macaddr\" value: \"%s\"", str))); errmsg("invalid octet value in \"macaddr\" value: \"%s\"", str)));

View File

@ -35,7 +35,7 @@
#define lobits(addr) \ #define lobits(addr) \
((unsigned long)(((addr)->e<<24) | ((addr)->f<<16) | ((addr)->g<<8) | ((addr)->h))) ((unsigned long)(((addr)->e<<24) | ((addr)->f<<16) | ((addr)->g<<8) | ((addr)->h)))
static unsigned char hex2_to_uchar(const unsigned char *ptr, const unsigned char *str); static unsigned char hex2_to_uchar(const unsigned char *ptr, bool *badhex);
static const signed char hexlookup[128] = { static const signed char hexlookup[128] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
@ -51,16 +51,13 @@ static const signed char hexlookup[128] = {
/* /*
* hex2_to_uchar - convert 2 hex digits to a byte (unsigned char) * hex2_to_uchar - convert 2 hex digits to a byte (unsigned char)
* *
* This will ereport() if the end of the string is reached ('\0' found), or if * Sets *badhex to true if the end of the string is reached ('\0' found), or if
* either character is not a valid hex digit. * either character is not a valid hex digit.
*
* ptr is the pointer to where the digits to convert are in the string, str is
* the entire string, which is used only for error reporting.
*/ */
static inline unsigned char static inline unsigned char
hex2_to_uchar(const unsigned char *ptr, const unsigned char *str) hex2_to_uchar(const unsigned char *ptr, bool *badhex)
{ {
unsigned char ret = 0; unsigned char ret;
signed char lookup; signed char lookup;
/* Handle the first character */ /* Handle the first character */
@ -88,12 +85,7 @@ hex2_to_uchar(const unsigned char *ptr, const unsigned char *str)
return ret; return ret;
invalid_input: invalid_input:
ereport(ERROR, *badhex = true;
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for type %s: \"%s\"", "macaddr8",
str)));
/* We do not actually reach here */
return 0; return 0;
} }
@ -104,7 +96,9 @@ Datum
macaddr8_in(PG_FUNCTION_ARGS) macaddr8_in(PG_FUNCTION_ARGS)
{ {
const unsigned char *str = (unsigned char *) PG_GETARG_CSTRING(0); const unsigned char *str = (unsigned char *) PG_GETARG_CSTRING(0);
Node *escontext = fcinfo->context;
const unsigned char *ptr = str; const unsigned char *ptr = str;
bool badhex = false;
macaddr8 *result; macaddr8 *result;
unsigned char a = 0, unsigned char a = 0,
b = 0, b = 0,
@ -136,37 +130,37 @@ macaddr8_in(PG_FUNCTION_ARGS)
switch (count) switch (count)
{ {
case 1: case 1:
a = hex2_to_uchar(ptr, str); a = hex2_to_uchar(ptr, &badhex);
break; break;
case 2: case 2:
b = hex2_to_uchar(ptr, str); b = hex2_to_uchar(ptr, &badhex);
break; break;
case 3: case 3:
c = hex2_to_uchar(ptr, str); c = hex2_to_uchar(ptr, &badhex);
break; break;
case 4: case 4:
d = hex2_to_uchar(ptr, str); d = hex2_to_uchar(ptr, &badhex);
break; break;
case 5: case 5:
e = hex2_to_uchar(ptr, str); e = hex2_to_uchar(ptr, &badhex);
break; break;
case 6: case 6:
f = hex2_to_uchar(ptr, str); f = hex2_to_uchar(ptr, &badhex);
break; break;
case 7: case 7:
g = hex2_to_uchar(ptr, str); g = hex2_to_uchar(ptr, &badhex);
break; break;
case 8: case 8:
h = hex2_to_uchar(ptr, str); h = hex2_to_uchar(ptr, &badhex);
break; break;
default: default:
/* must be trailing garbage... */ /* must be trailing garbage... */
ereport(ERROR, goto fail;
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for type %s: \"%s\"", "macaddr8",
str)));
} }
if (badhex)
goto fail;
/* Move forward to where the next byte should be */ /* Move forward to where the next byte should be */
ptr += 2; ptr += 2;
@ -179,10 +173,7 @@ macaddr8_in(PG_FUNCTION_ARGS)
/* Have to use the same spacer throughout */ /* Have to use the same spacer throughout */
else if (spacer != *ptr) else if (spacer != *ptr)
ereport(ERROR, goto fail;
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for type %s: \"%s\"", "macaddr8",
str)));
/* move past the spacer */ /* move past the spacer */
ptr++; ptr++;
@ -197,10 +188,7 @@ macaddr8_in(PG_FUNCTION_ARGS)
/* If we found a space and then non-space, it's invalid */ /* If we found a space and then non-space, it's invalid */
if (*ptr) if (*ptr)
ereport(ERROR, goto fail;
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for type %s: \"%s\"", "macaddr8",
str)));
} }
} }
} }
@ -216,10 +204,7 @@ macaddr8_in(PG_FUNCTION_ARGS)
e = 0xFE; e = 0xFE;
} }
else if (count != 8) else if (count != 8)
ereport(ERROR, goto fail;
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for type %s: \"%s\"", "macaddr8",
str)));
result = (macaddr8 *) palloc0(sizeof(macaddr8)); result = (macaddr8 *) palloc0(sizeof(macaddr8));
@ -233,6 +218,12 @@ macaddr8_in(PG_FUNCTION_ARGS)
result->h = h; result->h = h;
PG_RETURN_MACADDR8_P(result); PG_RETURN_MACADDR8_P(result);
fail:
ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for type %s: \"%s\"", "macaddr8",
str)));
} }
/* /*

View File

@ -72,7 +72,7 @@ static inet *internal_inetpl(inet *ip, int64 addend);
* Common INET/CIDR input routine * Common INET/CIDR input routine
*/ */
static inet * static inet *
network_in(char *src, bool is_cidr) network_in(char *src, bool is_cidr, Node *escontext)
{ {
int bits; int bits;
inet *dst; inet *dst;
@ -93,7 +93,7 @@ network_in(char *src, bool is_cidr)
bits = pg_inet_net_pton(ip_family(dst), src, ip_addr(dst), bits = pg_inet_net_pton(ip_family(dst), src, ip_addr(dst),
is_cidr ? ip_addrsize(dst) : -1); is_cidr ? ip_addrsize(dst) : -1);
if ((bits < 0) || (bits > ip_maxbits(dst))) if ((bits < 0) || (bits > ip_maxbits(dst)))
ereport(ERROR, ereturn(escontext, NULL,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
/* translator: first %s is inet or cidr */ /* translator: first %s is inet or cidr */
errmsg("invalid input syntax for type %s: \"%s\"", errmsg("invalid input syntax for type %s: \"%s\"",
@ -105,7 +105,7 @@ network_in(char *src, bool is_cidr)
if (is_cidr) if (is_cidr)
{ {
if (!addressOK(ip_addr(dst), bits, ip_family(dst))) if (!addressOK(ip_addr(dst), bits, ip_family(dst)))
ereport(ERROR, ereturn(escontext, NULL,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid cidr value: \"%s\"", src), errmsg("invalid cidr value: \"%s\"", src),
errdetail("Value has bits set to right of mask."))); errdetail("Value has bits set to right of mask.")));
@ -122,7 +122,7 @@ inet_in(PG_FUNCTION_ARGS)
{ {
char *src = PG_GETARG_CSTRING(0); char *src = PG_GETARG_CSTRING(0);
PG_RETURN_INET_P(network_in(src, false)); PG_RETURN_INET_P(network_in(src, false, fcinfo->context));
} }
Datum Datum
@ -130,7 +130,7 @@ cidr_in(PG_FUNCTION_ARGS)
{ {
char *src = PG_GETARG_CSTRING(0); char *src = PG_GETARG_CSTRING(0);
PG_RETURN_INET_P(network_in(src, true)); PG_RETURN_INET_P(network_in(src, true, fcinfo->context));
} }
@ -1742,7 +1742,7 @@ inet_client_addr(PG_FUNCTION_ARGS)
clean_ipv6_addr(port->raddr.addr.ss_family, remote_host); clean_ipv6_addr(port->raddr.addr.ss_family, remote_host);
PG_RETURN_INET_P(network_in(remote_host, false)); PG_RETURN_INET_P(network_in(remote_host, false, NULL));
} }
@ -1814,7 +1814,7 @@ inet_server_addr(PG_FUNCTION_ARGS)
clean_ipv6_addr(port->laddr.addr.ss_family, local_host); clean_ipv6_addr(port->laddr.addr.ss_family, local_host);
PG_RETURN_INET_P(network_in(local_host, false)); PG_RETURN_INET_P(network_in(local_host, false, NULL));
} }

View File

@ -147,11 +147,11 @@ Datum
bit_in(PG_FUNCTION_ARGS) bit_in(PG_FUNCTION_ARGS)
{ {
char *input_string = PG_GETARG_CSTRING(0); char *input_string = PG_GETARG_CSTRING(0);
#ifdef NOT_USED #ifdef NOT_USED
Oid typelem = PG_GETARG_OID(1); Oid typelem = PG_GETARG_OID(1);
#endif #endif
int32 atttypmod = PG_GETARG_INT32(2); int32 atttypmod = PG_GETARG_INT32(2);
Node *escontext = fcinfo->context;
VarBit *result; /* The resulting bit string */ VarBit *result; /* The resulting bit string */
char *sp; /* pointer into the character string */ char *sp; /* pointer into the character string */
bits8 *r; /* pointer into the result */ bits8 *r; /* pointer into the result */
@ -193,7 +193,7 @@ bit_in(PG_FUNCTION_ARGS)
else else
{ {
if (slen > VARBITMAXLEN / 4) if (slen > VARBITMAXLEN / 4)
ereport(ERROR, ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("bit string length exceeds the maximum allowed (%d)", errmsg("bit string length exceeds the maximum allowed (%d)",
VARBITMAXLEN))); VARBITMAXLEN)));
@ -207,7 +207,7 @@ bit_in(PG_FUNCTION_ARGS)
if (atttypmod <= 0) if (atttypmod <= 0)
atttypmod = bitlen; atttypmod = bitlen;
else if (bitlen != atttypmod) else if (bitlen != atttypmod)
ereport(ERROR, ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_STRING_DATA_LENGTH_MISMATCH), (errcode(ERRCODE_STRING_DATA_LENGTH_MISMATCH),
errmsg("bit string length %d does not match type bit(%d)", errmsg("bit string length %d does not match type bit(%d)",
bitlen, atttypmod))); bitlen, atttypmod)));
@ -229,7 +229,7 @@ bit_in(PG_FUNCTION_ARGS)
if (*sp == '1') if (*sp == '1')
*r |= x; *r |= x;
else if (*sp != '0') else if (*sp != '0')
ereport(ERROR, ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("\"%.*s\" is not a valid binary digit", errmsg("\"%.*s\" is not a valid binary digit",
pg_mblen(sp), sp))); pg_mblen(sp), sp)));
@ -254,7 +254,7 @@ bit_in(PG_FUNCTION_ARGS)
else if (*sp >= 'a' && *sp <= 'f') else if (*sp >= 'a' && *sp <= 'f')
x = (bits8) (*sp - 'a') + 10; x = (bits8) (*sp - 'a') + 10;
else else
ereport(ERROR, ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("\"%.*s\" is not a valid hexadecimal digit", errmsg("\"%.*s\" is not a valid hexadecimal digit",
pg_mblen(sp), sp))); pg_mblen(sp), sp)));
@ -452,11 +452,11 @@ Datum
varbit_in(PG_FUNCTION_ARGS) varbit_in(PG_FUNCTION_ARGS)
{ {
char *input_string = PG_GETARG_CSTRING(0); char *input_string = PG_GETARG_CSTRING(0);
#ifdef NOT_USED #ifdef NOT_USED
Oid typelem = PG_GETARG_OID(1); Oid typelem = PG_GETARG_OID(1);
#endif #endif
int32 atttypmod = PG_GETARG_INT32(2); int32 atttypmod = PG_GETARG_INT32(2);
Node *escontext = fcinfo->context;
VarBit *result; /* The resulting bit string */ VarBit *result; /* The resulting bit string */
char *sp; /* pointer into the character string */ char *sp; /* pointer into the character string */
bits8 *r; /* pointer into the result */ bits8 *r; /* pointer into the result */
@ -494,7 +494,7 @@ varbit_in(PG_FUNCTION_ARGS)
else else
{ {
if (slen > VARBITMAXLEN / 4) if (slen > VARBITMAXLEN / 4)
ereport(ERROR, ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("bit string length exceeds the maximum allowed (%d)", errmsg("bit string length exceeds the maximum allowed (%d)",
VARBITMAXLEN))); VARBITMAXLEN)));
@ -508,7 +508,7 @@ varbit_in(PG_FUNCTION_ARGS)
if (atttypmod <= 0) if (atttypmod <= 0)
atttypmod = bitlen; atttypmod = bitlen;
else if (bitlen > atttypmod) else if (bitlen > atttypmod)
ereport(ERROR, ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION), (errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION),
errmsg("bit string too long for type bit varying(%d)", errmsg("bit string too long for type bit varying(%d)",
atttypmod))); atttypmod)));
@ -530,7 +530,7 @@ varbit_in(PG_FUNCTION_ARGS)
if (*sp == '1') if (*sp == '1')
*r |= x; *r |= x;
else if (*sp != '0') else if (*sp != '0')
ereport(ERROR, ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("\"%.*s\" is not a valid binary digit", errmsg("\"%.*s\" is not a valid binary digit",
pg_mblen(sp), sp))); pg_mblen(sp), sp)));
@ -555,7 +555,7 @@ varbit_in(PG_FUNCTION_ARGS)
else if (*sp >= 'a' && *sp <= 'f') else if (*sp >= 'a' && *sp <= 'f')
x = (bits8) (*sp - 'a') + 10; x = (bits8) (*sp - 'a') + 10;
else else
ereport(ERROR, ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("\"%.*s\" is not a valid hexadecimal digit", errmsg("\"%.*s\" is not a valid hexadecimal digit",
pg_mblen(sp), sp))); pg_mblen(sp), sp)));

View File

@ -746,3 +746,64 @@ TABLE bit_defaults;
1001 | 0101 | 1001 | 0101 1001 | 0101 | 1001 | 0101
(1 row) (1 row)
-- test non-error-throwing API for some core types
SELECT pg_input_is_valid('01010001', 'bit(10)');
pg_input_is_valid
-------------------
f
(1 row)
SELECT pg_input_error_message('01010001', 'bit(10)');
pg_input_error_message
-------------------------------------------------
bit string length 8 does not match type bit(10)
(1 row)
SELECT pg_input_is_valid('01010Z01', 'bit(8)');
pg_input_is_valid
-------------------
f
(1 row)
SELECT pg_input_error_message('01010Z01', 'bit(8)');
pg_input_error_message
---------------------------------
"Z" is not a valid binary digit
(1 row)
SELECT pg_input_is_valid('x01010Z01', 'bit(32)');
pg_input_is_valid
-------------------
f
(1 row)
SELECT pg_input_error_message('x01010Z01', 'bit(32)');
pg_input_error_message
--------------------------------------
"Z" is not a valid hexadecimal digit
(1 row)
SELECT pg_input_is_valid('01010Z01', 'varbit');
pg_input_is_valid
-------------------
f
(1 row)
SELECT pg_input_error_message('01010Z01', 'varbit');
pg_input_error_message
---------------------------------
"Z" is not a valid binary digit
(1 row)
SELECT pg_input_is_valid('x01010Z01', 'varbit');
pg_input_is_valid
-------------------
f
(1 row)
SELECT pg_input_error_message('x01010Z01', 'varbit');
pg_input_error_message
--------------------------------------
"Z" is not a valid hexadecimal digit
(1 row)

View File

@ -1056,3 +1056,40 @@ SELECT a FROM (VALUES
ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
(91 rows) (91 rows)
-- test non-error-throwing API for some core types
SELECT pg_input_is_valid('1234', 'cidr');
pg_input_is_valid
-------------------
f
(1 row)
SELECT pg_input_error_message('1234', 'cidr');
pg_input_error_message
--------------------------------------------
invalid input syntax for type cidr: "1234"
(1 row)
SELECT pg_input_is_valid('192.168.198.200/24', 'cidr');
pg_input_is_valid
-------------------
f
(1 row)
SELECT pg_input_error_message('192.168.198.200/24', 'cidr');
pg_input_error_message
------------------------------------------
invalid cidr value: "192.168.198.200/24"
(1 row)
SELECT pg_input_is_valid('1234', 'inet');
pg_input_is_valid
-------------------
f
(1 row)
SELECT pg_input_error_message('1234', 'inet');
pg_input_error_message
--------------------------------------------
invalid input syntax for type inet: "1234"
(1 row)

View File

@ -158,3 +158,28 @@ SELECT b | '01:02:03:04:05:06' FROM macaddr_data;
(12 rows) (12 rows)
DROP TABLE macaddr_data; DROP TABLE macaddr_data;
-- test non-error-throwing API for some core types
SELECT pg_input_is_valid('08:00:2b:01:02:ZZ', 'macaddr');
pg_input_is_valid
-------------------
f
(1 row)
SELECT pg_input_error_message('08:00:2b:01:02:ZZ', 'macaddr');
pg_input_error_message
------------------------------------------------------------
invalid input syntax for type macaddr: "08:00:2b:01:02:ZZ"
(1 row)
SELECT pg_input_is_valid('08:00:2b:01:02:', 'macaddr');
pg_input_is_valid
-------------------
f
(1 row)
SELECT pg_input_error_message('08:00:2b:01:02:', 'macaddr');
pg_input_error_message
----------------------------------------------------------
invalid input syntax for type macaddr: "08:00:2b:01:02:"
(1 row)

View File

@ -352,3 +352,28 @@ SELECT b | '01:02:03:04:05:06' FROM macaddr8_data;
(20 rows) (20 rows)
DROP TABLE macaddr8_data; DROP TABLE macaddr8_data;
-- test non-error-throwing API for some core types
SELECT pg_input_is_valid('08:00:2b:01:02:03:04:ZZ', 'macaddr8');
pg_input_is_valid
-------------------
f
(1 row)
SELECT pg_input_error_message('08:00:2b:01:02:03:04:ZZ', 'macaddr8');
pg_input_error_message
-------------------------------------------------------------------
invalid input syntax for type macaddr8: "08:00:2b:01:02:03:04:ZZ"
(1 row)
SELECT pg_input_is_valid('08:00:2b:01:02:03:04:', 'macaddr8');
pg_input_is_valid
-------------------
f
(1 row)
SELECT pg_input_error_message('08:00:2b:01:02:03:04:', 'macaddr8');
pg_input_error_message
-----------------------------------------------------------------
invalid input syntax for type macaddr8: "08:00:2b:01:02:03:04:"
(1 row)

View File

@ -229,3 +229,16 @@ CREATE TABLE bit_defaults(
\d bit_defaults \d bit_defaults
INSERT INTO bit_defaults DEFAULT VALUES; INSERT INTO bit_defaults DEFAULT VALUES;
TABLE bit_defaults; TABLE bit_defaults;
-- test non-error-throwing API for some core types
SELECT pg_input_is_valid('01010001', 'bit(10)');
SELECT pg_input_error_message('01010001', 'bit(10)');
SELECT pg_input_is_valid('01010Z01', 'bit(8)');
SELECT pg_input_error_message('01010Z01', 'bit(8)');
SELECT pg_input_is_valid('x01010Z01', 'bit(32)');
SELECT pg_input_error_message('x01010Z01', 'bit(32)');
SELECT pg_input_is_valid('01010Z01', 'varbit');
SELECT pg_input_error_message('01010Z01', 'varbit');
SELECT pg_input_is_valid('x01010Z01', 'varbit');
SELECT pg_input_error_message('x01010Z01', 'varbit');

View File

@ -252,3 +252,12 @@ SELECT a FROM (VALUES
('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/0'::inet), ('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/0'::inet),
('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128'::inet) ('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128'::inet)
) AS i(a) ORDER BY a; ) AS i(a) ORDER BY a;
-- test non-error-throwing API for some core types
SELECT pg_input_is_valid('1234', 'cidr');
SELECT pg_input_error_message('1234', 'cidr');
SELECT pg_input_is_valid('192.168.198.200/24', 'cidr');
SELECT pg_input_error_message('192.168.198.200/24', 'cidr');
SELECT pg_input_is_valid('1234', 'inet');
SELECT pg_input_error_message('1234', 'inet');

View File

@ -41,3 +41,9 @@ SELECT b & '00:00:00:ff:ff:ff' FROM macaddr_data;
SELECT b | '01:02:03:04:05:06' FROM macaddr_data; SELECT b | '01:02:03:04:05:06' FROM macaddr_data;
DROP TABLE macaddr_data; DROP TABLE macaddr_data;
-- test non-error-throwing API for some core types
SELECT pg_input_is_valid('08:00:2b:01:02:ZZ', 'macaddr');
SELECT pg_input_error_message('08:00:2b:01:02:ZZ', 'macaddr');
SELECT pg_input_is_valid('08:00:2b:01:02:', 'macaddr');
SELECT pg_input_error_message('08:00:2b:01:02:', 'macaddr');

View File

@ -87,3 +87,9 @@ SELECT b & '00:00:00:ff:ff:ff' FROM macaddr8_data;
SELECT b | '01:02:03:04:05:06' FROM macaddr8_data; SELECT b | '01:02:03:04:05:06' FROM macaddr8_data;
DROP TABLE macaddr8_data; DROP TABLE macaddr8_data;
-- test non-error-throwing API for some core types
SELECT pg_input_is_valid('08:00:2b:01:02:03:04:ZZ', 'macaddr8');
SELECT pg_input_error_message('08:00:2b:01:02:03:04:ZZ', 'macaddr8');
SELECT pg_input_is_valid('08:00:2b:01:02:03:04:', 'macaddr8');
SELECT pg_input_error_message('08:00:2b:01:02:03:04:', 'macaddr8');