mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-02 10:40:57 +08:00
Fixed improved vector text representation for Postgres < 12
This commit is contained in:
17
src/vector.c
17
src/vector.c
@@ -5,7 +5,6 @@
|
||||
#include "vector.h"
|
||||
#include "fmgr.h"
|
||||
#include "catalog/pg_type.h"
|
||||
#include "common/shortest_dec.h"
|
||||
#include "lib/stringinfo.h"
|
||||
#include "libpq/pqformat.h"
|
||||
#include "utils/array.h"
|
||||
@@ -14,7 +13,10 @@
|
||||
#include "utils/numeric.h"
|
||||
|
||||
#if PG_VERSION_NUM >= 120000
|
||||
#include "common/shortest_dec.h"
|
||||
#include "utils/float.h"
|
||||
#else
|
||||
#include <float.h>
|
||||
#endif
|
||||
|
||||
#if PG_VERSION_NUM < 130000
|
||||
@@ -195,6 +197,15 @@ vector_out(PG_FUNCTION_ARGS)
|
||||
int i;
|
||||
int n;
|
||||
|
||||
#if PG_VERSION_NUM < 120000
|
||||
int ndig = FLT_DIG + extra_float_digits;
|
||||
|
||||
if (ndig < 1)
|
||||
ndig = 1;
|
||||
|
||||
#define FLOAT_SHORTEST_DECIMAL_LEN ndig + 10
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Need:
|
||||
*
|
||||
@@ -218,7 +229,11 @@ vector_out(PG_FUNCTION_ARGS)
|
||||
ptr++;
|
||||
}
|
||||
|
||||
#if PG_VERSION_NUM >= 120000
|
||||
n = float_to_shortest_decimal_bufn(vector->x[i], ptr);
|
||||
#else
|
||||
n = sprintf(ptr, "%.*g", ndig, vector->x[i]);
|
||||
#endif
|
||||
ptr += n;
|
||||
}
|
||||
*ptr = ']';
|
||||
|
||||
Reference in New Issue
Block a user