Is storing them in a CUBE
type field and then getting euclidean distance, (using <->
) the only way?
I can not save them as a list of floats, since i get: "can't adapt type numpyndarray"
Can not cast a type bytea to type cube, either.
Cube extension is installed, i can convert the list to type bytea using psycopg2, but nothing seems to work.
What am i missing?
I'm using postgresql 10.4, python 3, postgresapp 2.1.4 and postico
Best Answer
Quick google search shows numpyndarray as being SciPy's "N-dimensional array". This can hold what PostgreSQL calls a cube and vise-versa.
You assume that there is a translation layer that takes
numpyndarray
and converts the types to acube
for you. There likely isn't. You could provide such a layer, or extend your PostgreSQL connector/driver to provide that layer (see this for information on psycopg), but shy of that you'll have to go by way oftext
.That means you'll be calling
cube()
or providing a text string and a cast to cube.Your job is to convert
numpyndarray
to a textual representation like the above, and then to convert it back again.Cubes can also be constructed as
float[]
which you may find easier if your DB layer supports that,