mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-14 00:26:55 +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 "vector.h"
|
||||||
#include "fmgr.h"
|
#include "fmgr.h"
|
||||||
#include "catalog/pg_type.h"
|
#include "catalog/pg_type.h"
|
||||||
#include "common/shortest_dec.h"
|
|
||||||
#include "lib/stringinfo.h"
|
#include "lib/stringinfo.h"
|
||||||
#include "libpq/pqformat.h"
|
#include "libpq/pqformat.h"
|
||||||
#include "utils/array.h"
|
#include "utils/array.h"
|
||||||
@@ -14,7 +13,10 @@
|
|||||||
#include "utils/numeric.h"
|
#include "utils/numeric.h"
|
||||||
|
|
||||||
#if PG_VERSION_NUM >= 120000
|
#if PG_VERSION_NUM >= 120000
|
||||||
|
#include "common/shortest_dec.h"
|
||||||
#include "utils/float.h"
|
#include "utils/float.h"
|
||||||
|
#else
|
||||||
|
#include <float.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if PG_VERSION_NUM < 130000
|
#if PG_VERSION_NUM < 130000
|
||||||
@@ -195,6 +197,15 @@ vector_out(PG_FUNCTION_ARGS)
|
|||||||
int i;
|
int i;
|
||||||
int n;
|
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:
|
* Need:
|
||||||
*
|
*
|
||||||
@@ -218,7 +229,11 @@ vector_out(PG_FUNCTION_ARGS)
|
|||||||
ptr++;
|
ptr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if PG_VERSION_NUM >= 120000
|
||||||
n = float_to_shortest_decimal_bufn(vector->x[i], ptr);
|
n = float_to_shortest_decimal_bufn(vector->x[i], ptr);
|
||||||
|
#else
|
||||||
|
n = sprintf(ptr, "%.*g", ndig, vector->x[i]);
|
||||||
|
#endif
|
||||||
ptr += n;
|
ptr += n;
|
||||||
}
|
}
|
||||||
*ptr = ']';
|
*ptr = ']';
|
||||||
|
|||||||
Reference in New Issue
Block a user