mirror of
https://github.com/postgres/postgres.git
synced 2025-06-27 23:21:58 +03:00
Convert a few more datatype input functions to report errors softly.
Convert the remaining string-category input functions (bpcharin, varcharin, byteain) to the new style. Discussion: https://postgr.es/m/3038346.1671060258@sss.pgh.pa.us
This commit is contained in:
@ -171,8 +171,8 @@ hex_encode(const char *src, size_t len, char *dst)
|
|||||||
return (uint64) len * 2;
|
return (uint64) len * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline char
|
static inline bool
|
||||||
get_hex(const char *cp)
|
get_hex(const char *cp, char *out)
|
||||||
{
|
{
|
||||||
unsigned char c = (unsigned char) *cp;
|
unsigned char c = (unsigned char) *cp;
|
||||||
int res = -1;
|
int res = -1;
|
||||||
@ -180,17 +180,19 @@ get_hex(const char *cp)
|
|||||||
if (c < 127)
|
if (c < 127)
|
||||||
res = hexlookup[c];
|
res = hexlookup[c];
|
||||||
|
|
||||||
if (res < 0)
|
*out = (char) res;
|
||||||
ereport(ERROR,
|
|
||||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
|
||||||
errmsg("invalid hexadecimal digit: \"%.*s\"",
|
|
||||||
pg_mblen(cp), cp)));
|
|
||||||
|
|
||||||
return (char) res;
|
return (res >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64
|
uint64
|
||||||
hex_decode(const char *src, size_t len, char *dst)
|
hex_decode(const char *src, size_t len, char *dst)
|
||||||
|
{
|
||||||
|
return hex_decode_safe(src, len, dst, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64
|
||||||
|
hex_decode_safe(const char *src, size_t len, char *dst, Node *escontext)
|
||||||
{
|
{
|
||||||
const char *s,
|
const char *s,
|
||||||
*srcend;
|
*srcend;
|
||||||
@ -208,16 +210,23 @@ hex_decode(const char *src, size_t len, char *dst)
|
|||||||
s++;
|
s++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
v1 = get_hex(s) << 4;
|
if (!get_hex(s, &v1))
|
||||||
|
ereturn(escontext, 0,
|
||||||
|
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||||
|
errmsg("invalid hexadecimal digit: \"%.*s\"",
|
||||||
|
pg_mblen(s), s)));
|
||||||
s++;
|
s++;
|
||||||
if (s >= srcend)
|
if (s >= srcend)
|
||||||
ereport(ERROR,
|
ereturn(escontext, 0,
|
||||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||||
errmsg("invalid hexadecimal data: odd number of digits")));
|
errmsg("invalid hexadecimal data: odd number of digits")));
|
||||||
|
if (!get_hex(s, &v2))
|
||||||
v2 = get_hex(s);
|
ereturn(escontext, 0,
|
||||||
|
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||||
|
errmsg("invalid hexadecimal digit: \"%.*s\"",
|
||||||
|
pg_mblen(s), s)));
|
||||||
s++;
|
s++;
|
||||||
*p++ = v1 | v2;
|
*p++ = (v1 << 4) | v2;
|
||||||
}
|
}
|
||||||
|
|
||||||
return p - dst;
|
return p - dst;
|
||||||
|
@ -122,9 +122,13 @@ anychar_typmodout(int32 typmod)
|
|||||||
*
|
*
|
||||||
* If the input string is too long, raise an error, unless the extra
|
* If the input string is too long, raise an error, unless the extra
|
||||||
* characters are spaces, in which case they're truncated. (per SQL)
|
* characters are spaces, in which case they're truncated. (per SQL)
|
||||||
|
*
|
||||||
|
* If escontext points to an ErrorSaveContext node, that is filled instead
|
||||||
|
* of throwing an error; the caller must check SOFT_ERROR_OCCURRED()
|
||||||
|
* to detect errors.
|
||||||
*/
|
*/
|
||||||
static BpChar *
|
static BpChar *
|
||||||
bpchar_input(const char *s, size_t len, int32 atttypmod)
|
bpchar_input(const char *s, size_t len, int32 atttypmod, Node *escontext)
|
||||||
{
|
{
|
||||||
BpChar *result;
|
BpChar *result;
|
||||||
char *r;
|
char *r;
|
||||||
@ -153,7 +157,7 @@ bpchar_input(const char *s, size_t len, int32 atttypmod)
|
|||||||
for (j = mbmaxlen; j < len; j++)
|
for (j = mbmaxlen; j < len; j++)
|
||||||
{
|
{
|
||||||
if (s[j] != ' ')
|
if (s[j] != ' ')
|
||||||
ereport(ERROR,
|
ereturn(escontext, NULL,
|
||||||
(errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION),
|
(errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION),
|
||||||
errmsg("value too long for type character(%d)",
|
errmsg("value too long for type character(%d)",
|
||||||
(int) maxlen)));
|
(int) maxlen)));
|
||||||
@ -195,14 +199,13 @@ Datum
|
|||||||
bpcharin(PG_FUNCTION_ARGS)
|
bpcharin(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
char *s = PG_GETARG_CSTRING(0);
|
char *s = 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);
|
||||||
BpChar *result;
|
BpChar *result;
|
||||||
|
|
||||||
result = bpchar_input(s, strlen(s), atttypmod);
|
result = bpchar_input(s, strlen(s), atttypmod, fcinfo->context);
|
||||||
PG_RETURN_BPCHAR_P(result);
|
PG_RETURN_BPCHAR_P(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,7 +231,6 @@ Datum
|
|||||||
bpcharrecv(PG_FUNCTION_ARGS)
|
bpcharrecv(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
|
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
|
||||||
|
|
||||||
#ifdef NOT_USED
|
#ifdef NOT_USED
|
||||||
Oid typelem = PG_GETARG_OID(1);
|
Oid typelem = PG_GETARG_OID(1);
|
||||||
#endif
|
#endif
|
||||||
@ -238,7 +240,7 @@ bpcharrecv(PG_FUNCTION_ARGS)
|
|||||||
int nbytes;
|
int nbytes;
|
||||||
|
|
||||||
str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
|
str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
|
||||||
result = bpchar_input(str, nbytes, atttypmod);
|
result = bpchar_input(str, nbytes, atttypmod, NULL);
|
||||||
pfree(str);
|
pfree(str);
|
||||||
PG_RETURN_BPCHAR_P(result);
|
PG_RETURN_BPCHAR_P(result);
|
||||||
}
|
}
|
||||||
@ -448,11 +450,12 @@ bpchartypmodout(PG_FUNCTION_ARGS)
|
|||||||
* If the input string is too long, raise an error, unless the extra
|
* If the input string is too long, raise an error, unless the extra
|
||||||
* characters are spaces, in which case they're truncated. (per SQL)
|
* characters are spaces, in which case they're truncated. (per SQL)
|
||||||
*
|
*
|
||||||
* Uses the C string to text conversion function, which is only appropriate
|
* If escontext points to an ErrorSaveContext node, that is filled instead
|
||||||
* if VarChar and text are equivalent types.
|
* of throwing an error; the caller must check SOFT_ERROR_OCCURRED()
|
||||||
|
* to detect errors.
|
||||||
*/
|
*/
|
||||||
static VarChar *
|
static VarChar *
|
||||||
varchar_input(const char *s, size_t len, int32 atttypmod)
|
varchar_input(const char *s, size_t len, int32 atttypmod, Node *escontext)
|
||||||
{
|
{
|
||||||
VarChar *result;
|
VarChar *result;
|
||||||
size_t maxlen;
|
size_t maxlen;
|
||||||
@ -468,7 +471,7 @@ varchar_input(const char *s, size_t len, int32 atttypmod)
|
|||||||
for (j = mbmaxlen; j < len; j++)
|
for (j = mbmaxlen; j < len; j++)
|
||||||
{
|
{
|
||||||
if (s[j] != ' ')
|
if (s[j] != ' ')
|
||||||
ereport(ERROR,
|
ereturn(escontext, NULL,
|
||||||
(errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION),
|
(errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION),
|
||||||
errmsg("value too long for type character varying(%d)",
|
errmsg("value too long for type character varying(%d)",
|
||||||
(int) maxlen)));
|
(int) maxlen)));
|
||||||
@ -477,6 +480,10 @@ varchar_input(const char *s, size_t len, int32 atttypmod)
|
|||||||
len = mbmaxlen;
|
len = mbmaxlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We can use cstring_to_text_with_len because VarChar and text are
|
||||||
|
* binary-compatible types.
|
||||||
|
*/
|
||||||
result = (VarChar *) cstring_to_text_with_len(s, len);
|
result = (VarChar *) cstring_to_text_with_len(s, len);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -489,14 +496,13 @@ Datum
|
|||||||
varcharin(PG_FUNCTION_ARGS)
|
varcharin(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
char *s = PG_GETARG_CSTRING(0);
|
char *s = 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);
|
||||||
VarChar *result;
|
VarChar *result;
|
||||||
|
|
||||||
result = varchar_input(s, strlen(s), atttypmod);
|
result = varchar_input(s, strlen(s), atttypmod, fcinfo->context);
|
||||||
PG_RETURN_VARCHAR_P(result);
|
PG_RETURN_VARCHAR_P(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -522,7 +528,6 @@ Datum
|
|||||||
varcharrecv(PG_FUNCTION_ARGS)
|
varcharrecv(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
|
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
|
||||||
|
|
||||||
#ifdef NOT_USED
|
#ifdef NOT_USED
|
||||||
Oid typelem = PG_GETARG_OID(1);
|
Oid typelem = PG_GETARG_OID(1);
|
||||||
#endif
|
#endif
|
||||||
@ -532,7 +537,7 @@ varcharrecv(PG_FUNCTION_ARGS)
|
|||||||
int nbytes;
|
int nbytes;
|
||||||
|
|
||||||
str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
|
str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
|
||||||
result = varchar_input(str, nbytes, atttypmod);
|
result = varchar_input(str, nbytes, atttypmod, NULL);
|
||||||
pfree(str);
|
pfree(str);
|
||||||
PG_RETURN_VARCHAR_P(result);
|
PG_RETURN_VARCHAR_P(result);
|
||||||
}
|
}
|
||||||
|
@ -295,6 +295,7 @@ Datum
|
|||||||
byteain(PG_FUNCTION_ARGS)
|
byteain(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
char *inputText = PG_GETARG_CSTRING(0);
|
char *inputText = PG_GETARG_CSTRING(0);
|
||||||
|
Node *escontext = fcinfo->context;
|
||||||
char *tp;
|
char *tp;
|
||||||
char *rp;
|
char *rp;
|
||||||
int bc;
|
int bc;
|
||||||
@ -307,7 +308,8 @@ byteain(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
bc = (len - 2) / 2 + VARHDRSZ; /* maximum possible length */
|
bc = (len - 2) / 2 + VARHDRSZ; /* maximum possible length */
|
||||||
result = palloc(bc);
|
result = palloc(bc);
|
||||||
bc = hex_decode(inputText + 2, len - 2, VARDATA(result));
|
bc = hex_decode_safe(inputText + 2, len - 2, VARDATA(result),
|
||||||
|
escontext);
|
||||||
SET_VARSIZE(result, bc + VARHDRSZ); /* actual length */
|
SET_VARSIZE(result, bc + VARHDRSZ); /* actual length */
|
||||||
|
|
||||||
PG_RETURN_BYTEA_P(result);
|
PG_RETURN_BYTEA_P(result);
|
||||||
@ -331,7 +333,7 @@ byteain(PG_FUNCTION_ARGS)
|
|||||||
/*
|
/*
|
||||||
* one backslash, not followed by another or ### valid octal
|
* one backslash, not followed by another or ### valid octal
|
||||||
*/
|
*/
|
||||||
ereport(ERROR,
|
ereturn(escontext, (Datum) 0,
|
||||||
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
|
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
|
||||||
errmsg("invalid input syntax for type %s", "bytea")));
|
errmsg("invalid input syntax for type %s", "bytea")));
|
||||||
}
|
}
|
||||||
@ -372,7 +374,7 @@ byteain(PG_FUNCTION_ARGS)
|
|||||||
/*
|
/*
|
||||||
* We should never get here. The first pass should not allow it.
|
* We should never get here. The first pass should not allow it.
|
||||||
*/
|
*/
|
||||||
ereport(ERROR,
|
ereturn(escontext, (Datum) 0,
|
||||||
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
|
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
|
||||||
errmsg("invalid input syntax for type %s", "bytea")));
|
errmsg("invalid input syntax for type %s", "bytea")));
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,8 @@ extern int errdomainconstraint(Oid datatypeOid, const char *conname);
|
|||||||
/* encode.c */
|
/* encode.c */
|
||||||
extern uint64 hex_encode(const char *src, size_t len, char *dst);
|
extern uint64 hex_encode(const char *src, size_t len, char *dst);
|
||||||
extern uint64 hex_decode(const char *src, size_t len, char *dst);
|
extern uint64 hex_decode(const char *src, size_t len, char *dst);
|
||||||
|
extern uint64 hex_decode_safe(const char *src, size_t len, char *dst,
|
||||||
|
Node *escontext);
|
||||||
|
|
||||||
/* int.c */
|
/* int.c */
|
||||||
extern int2vector *buildint2vector(const int16 *int2s, int n);
|
extern int2vector *buildint2vector(const int16 *int2s, int n);
|
||||||
|
@ -119,6 +119,25 @@ SELECT * FROM CHAR_TBL;
|
|||||||
abcd
|
abcd
|
||||||
(4 rows)
|
(4 rows)
|
||||||
|
|
||||||
|
-- Also try it with non-error-throwing API
|
||||||
|
SELECT pg_input_is_valid('abcd ', 'char(4)');
|
||||||
|
pg_input_is_valid
|
||||||
|
-------------------
|
||||||
|
t
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SELECT pg_input_is_valid('abcde', 'char(4)');
|
||||||
|
pg_input_is_valid
|
||||||
|
-------------------
|
||||||
|
f
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SELECT pg_input_error_message('abcde', 'char(4)');
|
||||||
|
pg_input_error_message
|
||||||
|
--------------------------------------
|
||||||
|
value too long for type character(4)
|
||||||
|
(1 row)
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Also test "char", which is an ad-hoc one-byte type. It can only
|
-- Also test "char", which is an ad-hoc one-byte type. It can only
|
||||||
-- really store ASCII characters, but we allow high-bit-set characters
|
-- really store ASCII characters, but we allow high-bit-set characters
|
||||||
|
@ -119,6 +119,25 @@ SELECT * FROM CHAR_TBL;
|
|||||||
abcd
|
abcd
|
||||||
(4 rows)
|
(4 rows)
|
||||||
|
|
||||||
|
-- Also try it with non-error-throwing API
|
||||||
|
SELECT pg_input_is_valid('abcd ', 'char(4)');
|
||||||
|
pg_input_is_valid
|
||||||
|
-------------------
|
||||||
|
t
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SELECT pg_input_is_valid('abcde', 'char(4)');
|
||||||
|
pg_input_is_valid
|
||||||
|
-------------------
|
||||||
|
f
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SELECT pg_input_error_message('abcde', 'char(4)');
|
||||||
|
pg_input_error_message
|
||||||
|
--------------------------------------
|
||||||
|
value too long for type character(4)
|
||||||
|
(1 row)
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Also test "char", which is an ad-hoc one-byte type. It can only
|
-- Also test "char", which is an ad-hoc one-byte type. It can only
|
||||||
-- really store ASCII characters, but we allow high-bit-set characters
|
-- really store ASCII characters, but we allow high-bit-set characters
|
||||||
|
@ -119,6 +119,25 @@ SELECT * FROM CHAR_TBL;
|
|||||||
abcd
|
abcd
|
||||||
(4 rows)
|
(4 rows)
|
||||||
|
|
||||||
|
-- Also try it with non-error-throwing API
|
||||||
|
SELECT pg_input_is_valid('abcd ', 'char(4)');
|
||||||
|
pg_input_is_valid
|
||||||
|
-------------------
|
||||||
|
t
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SELECT pg_input_is_valid('abcde', 'char(4)');
|
||||||
|
pg_input_is_valid
|
||||||
|
-------------------
|
||||||
|
f
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SELECT pg_input_error_message('abcde', 'char(4)');
|
||||||
|
pg_input_error_message
|
||||||
|
--------------------------------------
|
||||||
|
value too long for type character(4)
|
||||||
|
(1 row)
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Also test "char", which is an ad-hoc one-byte type. It can only
|
-- Also test "char", which is an ad-hoc one-byte type. It can only
|
||||||
-- really store ASCII characters, but we allow high-bit-set characters
|
-- really store ASCII characters, but we allow high-bit-set characters
|
||||||
|
@ -273,6 +273,31 @@ SELECT E'De\\123dBeEf'::bytea;
|
|||||||
DeSdBeEf
|
DeSdBeEf
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
-- Test non-error-throwing API too
|
||||||
|
SELECT pg_input_is_valid(E'\\xDeAdBeE', 'bytea');
|
||||||
|
pg_input_is_valid
|
||||||
|
-------------------
|
||||||
|
f
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SELECT pg_input_error_message(E'\\xDeAdBeE', 'bytea');
|
||||||
|
pg_input_error_message
|
||||||
|
------------------------------------------------
|
||||||
|
invalid hexadecimal data: odd number of digits
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SELECT pg_input_error_message(E'\\xDeAdBeEx', 'bytea');
|
||||||
|
pg_input_error_message
|
||||||
|
--------------------------------
|
||||||
|
invalid hexadecimal digit: "x"
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SELECT pg_input_error_message(E'foo\\99bar', 'bytea');
|
||||||
|
pg_input_error_message
|
||||||
|
-------------------------------------
|
||||||
|
invalid input syntax for type bytea
|
||||||
|
(1 row)
|
||||||
|
|
||||||
--
|
--
|
||||||
-- test conversions between various string types
|
-- test conversions between various string types
|
||||||
-- E021-10 implicit casting among the character data types
|
-- E021-10 implicit casting among the character data types
|
||||||
|
@ -111,3 +111,22 @@ SELECT * FROM VARCHAR_TBL;
|
|||||||
abcd
|
abcd
|
||||||
(4 rows)
|
(4 rows)
|
||||||
|
|
||||||
|
-- Also try it with non-error-throwing API
|
||||||
|
SELECT pg_input_is_valid('abcd ', 'varchar(4)');
|
||||||
|
pg_input_is_valid
|
||||||
|
-------------------
|
||||||
|
t
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SELECT pg_input_is_valid('abcde', 'varchar(4)');
|
||||||
|
pg_input_is_valid
|
||||||
|
-------------------
|
||||||
|
f
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SELECT pg_input_error_message('abcde', 'varchar(4)');
|
||||||
|
pg_input_error_message
|
||||||
|
----------------------------------------------
|
||||||
|
value too long for type character varying(4)
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
@ -111,3 +111,22 @@ SELECT * FROM VARCHAR_TBL;
|
|||||||
abcd
|
abcd
|
||||||
(4 rows)
|
(4 rows)
|
||||||
|
|
||||||
|
-- Also try it with non-error-throwing API
|
||||||
|
SELECT pg_input_is_valid('abcd ', 'varchar(4)');
|
||||||
|
pg_input_is_valid
|
||||||
|
-------------------
|
||||||
|
t
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SELECT pg_input_is_valid('abcde', 'varchar(4)');
|
||||||
|
pg_input_is_valid
|
||||||
|
-------------------
|
||||||
|
f
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SELECT pg_input_error_message('abcde', 'varchar(4)');
|
||||||
|
pg_input_error_message
|
||||||
|
----------------------------------------------
|
||||||
|
value too long for type character varying(4)
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
@ -111,3 +111,22 @@ SELECT * FROM VARCHAR_TBL;
|
|||||||
abcd
|
abcd
|
||||||
(4 rows)
|
(4 rows)
|
||||||
|
|
||||||
|
-- Also try it with non-error-throwing API
|
||||||
|
SELECT pg_input_is_valid('abcd ', 'varchar(4)');
|
||||||
|
pg_input_is_valid
|
||||||
|
-------------------
|
||||||
|
t
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SELECT pg_input_is_valid('abcde', 'varchar(4)');
|
||||||
|
pg_input_is_valid
|
||||||
|
-------------------
|
||||||
|
f
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SELECT pg_input_error_message('abcde', 'varchar(4)');
|
||||||
|
pg_input_error_message
|
||||||
|
----------------------------------------------
|
||||||
|
value too long for type character varying(4)
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
@ -72,6 +72,11 @@ INSERT INTO CHAR_TBL (f1) VALUES ('abcde');
|
|||||||
|
|
||||||
SELECT * FROM CHAR_TBL;
|
SELECT * FROM CHAR_TBL;
|
||||||
|
|
||||||
|
-- Also try it with non-error-throwing API
|
||||||
|
SELECT pg_input_is_valid('abcd ', 'char(4)');
|
||||||
|
SELECT pg_input_is_valid('abcde', 'char(4)');
|
||||||
|
SELECT pg_input_error_message('abcde', 'char(4)');
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Also test "char", which is an ad-hoc one-byte type. It can only
|
-- Also test "char", which is an ad-hoc one-byte type. It can only
|
||||||
-- really store ASCII characters, but we allow high-bit-set characters
|
-- really store ASCII characters, but we allow high-bit-set characters
|
||||||
|
@ -85,6 +85,12 @@ SELECT E'DeAdBeEf'::bytea;
|
|||||||
SELECT E'De\\000dBeEf'::bytea;
|
SELECT E'De\\000dBeEf'::bytea;
|
||||||
SELECT E'De\\123dBeEf'::bytea;
|
SELECT E'De\\123dBeEf'::bytea;
|
||||||
|
|
||||||
|
-- Test non-error-throwing API too
|
||||||
|
SELECT pg_input_is_valid(E'\\xDeAdBeE', 'bytea');
|
||||||
|
SELECT pg_input_error_message(E'\\xDeAdBeE', 'bytea');
|
||||||
|
SELECT pg_input_error_message(E'\\xDeAdBeEx', 'bytea');
|
||||||
|
SELECT pg_input_error_message(E'foo\\99bar', 'bytea');
|
||||||
|
|
||||||
--
|
--
|
||||||
-- test conversions between various string types
|
-- test conversions between various string types
|
||||||
-- E021-10 implicit casting among the character data types
|
-- E021-10 implicit casting among the character data types
|
||||||
|
@ -66,3 +66,8 @@ DROP TABLE VARCHAR_TBL;
|
|||||||
INSERT INTO VARCHAR_TBL (f1) VALUES ('abcde');
|
INSERT INTO VARCHAR_TBL (f1) VALUES ('abcde');
|
||||||
|
|
||||||
SELECT * FROM VARCHAR_TBL;
|
SELECT * FROM VARCHAR_TBL;
|
||||||
|
|
||||||
|
-- Also try it with non-error-throwing API
|
||||||
|
SELECT pg_input_is_valid('abcd ', 'varchar(4)');
|
||||||
|
SELECT pg_input_is_valid('abcde', 'varchar(4)');
|
||||||
|
SELECT pg_input_error_message('abcde', 'varchar(4)');
|
||||||
|
Reference in New Issue
Block a user