mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-09 22:30:58 +08:00
Improved error message for malformed vector literal - #153
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
## 0.4.4 (unreleased)
|
||||||
|
|
||||||
|
- Improved error message for malformed vector literal
|
||||||
|
|
||||||
## 0.4.3 (2023-06-10)
|
## 0.4.3 (2023-06-10)
|
||||||
|
|
||||||
- Improved cost estimation
|
- Improved cost estimation
|
||||||
|
|||||||
@@ -174,6 +174,7 @@ vector_in(PG_FUNCTION_ARGS)
|
|||||||
char *pt;
|
char *pt;
|
||||||
char *stringEnd;
|
char *stringEnd;
|
||||||
Vector *result;
|
Vector *result;
|
||||||
|
char *lit = pstrdup(str);
|
||||||
|
|
||||||
while (vector_isspace(*str))
|
while (vector_isspace(*str))
|
||||||
str++;
|
str++;
|
||||||
@@ -181,7 +182,7 @@ vector_in(PG_FUNCTION_ARGS)
|
|||||||
if (*str != '[')
|
if (*str != '[')
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
|
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
|
||||||
errmsg("malformed vector literal: \"%s\"", str),
|
errmsg("malformed vector literal: \"%s\"", lit),
|
||||||
errdetail("Vector contents must start with \"[\".")));
|
errdetail("Vector contents must start with \"[\".")));
|
||||||
|
|
||||||
str++;
|
str++;
|
||||||
@@ -219,7 +220,7 @@ vector_in(PG_FUNCTION_ARGS)
|
|||||||
if (*stringEnd != ']')
|
if (*stringEnd != ']')
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
|
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
|
||||||
errmsg("malformed vector literal"),
|
errmsg("malformed vector literal: \"%s\"", lit),
|
||||||
errdetail("Unexpected end of input.")));
|
errdetail("Unexpected end of input.")));
|
||||||
|
|
||||||
stringEnd++;
|
stringEnd++;
|
||||||
@@ -231,7 +232,7 @@ vector_in(PG_FUNCTION_ARGS)
|
|||||||
if (*stringEnd != '\0')
|
if (*stringEnd != '\0')
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
|
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
|
||||||
errmsg("malformed vector literal"),
|
errmsg("malformed vector literal: \"%s\"", lit),
|
||||||
errdetail("Junk after closing right brace.")));
|
errdetail("Junk after closing right brace.")));
|
||||||
|
|
||||||
if (dim < 1)
|
if (dim < 1)
|
||||||
@@ -239,6 +240,8 @@ vector_in(PG_FUNCTION_ARGS)
|
|||||||
(errcode(ERRCODE_DATA_EXCEPTION),
|
(errcode(ERRCODE_DATA_EXCEPTION),
|
||||||
errmsg("vector must have at least 1 dimension")));
|
errmsg("vector must have at least 1 dimension")));
|
||||||
|
|
||||||
|
pfree(lit);
|
||||||
|
|
||||||
CheckExpectedDim(typmod, dim);
|
CheckExpectedDim(typmod, dim);
|
||||||
|
|
||||||
result = InitVector(dim);
|
result = InitVector(dim);
|
||||||
|
|||||||
@@ -43,12 +43,12 @@ ERROR: infinite value not allowed in vector
|
|||||||
LINE 1: SELECT '[4e38,1]'::vector;
|
LINE 1: SELECT '[4e38,1]'::vector;
|
||||||
^
|
^
|
||||||
SELECT '[1,2,3'::vector;
|
SELECT '[1,2,3'::vector;
|
||||||
ERROR: malformed vector literal
|
ERROR: malformed vector literal: "[1,2,3"
|
||||||
LINE 1: SELECT '[1,2,3'::vector;
|
LINE 1: SELECT '[1,2,3'::vector;
|
||||||
^
|
^
|
||||||
DETAIL: Unexpected end of input.
|
DETAIL: Unexpected end of input.
|
||||||
SELECT '[1,2,3]9'::vector;
|
SELECT '[1,2,3]9'::vector;
|
||||||
ERROR: malformed vector literal
|
ERROR: malformed vector literal: "[1,2,3]9"
|
||||||
LINE 1: SELECT '[1,2,3]9'::vector;
|
LINE 1: SELECT '[1,2,3]9'::vector;
|
||||||
^
|
^
|
||||||
DETAIL: Junk after closing right brace.
|
DETAIL: Junk after closing right brace.
|
||||||
|
|||||||
Reference in New Issue
Block a user