fix: input function does not allow tailing spaces#148
fix: input function does not allow tailing spaces#148ankane merged 4 commits intopgvector:masterfrom
Conversation
Signed-off-by: yihong0618 <zouzou0208@gmail.com>
jkatz
left a comment
There was a problem hiding this comment.
This aligns with current PostgreSQL behavior with arrays, e.g.:
postgres=# SELECT '{1 , 2 }'::int[];
int4
-------
{1,2}
(1 row)
However, I'd recommend following the convention that PostgreSQL has with the array_isspace function for the character checking (which would have to be reimplemented, as it's static):
Here is an example of how it is used in the array_in code:
thanks will use @jkatz |
Signed-off-by: yihong0618 <zouzou0208@gmail.com>
src/vector.c
Outdated
| * https://github.com/postgres/postgres/blob/378d73ef204d0dcbeab834d52478e8cb90578ab7/src/backend/utils/adt/arrayfuncs.c#L438 | ||
| */ | ||
| static inline bool | ||
| array_isspace(char ch) |
src/vector.c
Outdated
|
|
||
| /* | ||
| * Note: we currently allow whitespace between, but not within, | ||
| * dimension items. |
There was a problem hiding this comment.
I'm not sure this comment makes sense for vectors, so let's remove it
ankane
left a comment
There was a problem hiding this comment.
Hi @yihong0618, thanks for reporting and the PR! Looks great. Added a few comments inline (accidentally submitted the first review early).
src/vector.c
Outdated
| CheckElement(x[dim]); | ||
| dim++; | ||
| // stringEnd is space is OK to support SELECT '[ 1 , 2 ]'::vector(2); | ||
| while (array_isspace((unsigned char)*stringEnd)) |
There was a problem hiding this comment.
seems we need that, this is handle [1 , 2 ] which has spaces between 1 and ,
There was a problem hiding this comment.
(unsigned char) shouldn't be needed. Also, I think it should come after the if (stringEnd == pt) check.
There was a problem hiding this comment.
copy that, thanks for the info~
test/sql/input.sql
Outdated
| SELECT '[1,2,3 ]'::vector; | ||
| SELECT '[1, 2, 3 ]'::vector; | ||
| SELECT '[1. , 2, 3 ]'::vector(3); | ||
| SELECT ' [1,2,3] '::vector(3); |
There was a problem hiding this comment.
I think we can combine this into a single test
Signed-off-by: yihong0618 <zouzou0208@gmail.com>
|
@ankane thanks very much for the review, the comments has been fixed now, and one CI on ubuntu seems failed, rerun and passed |
|
Awesome, big thanks @yihong0618! |
|
@ankane thanks for your great repo~ |
this fix #147
also add test case for it
passed CI can check: https://github.com/yihong0618/pgvector/actions/runs/5209060111