Skip to content

Instantly share code, notes, and snippets.

@felixhummel
Created February 20, 2024 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felixhummel/ee15c4eca9c3d17066ab30aa174d61c6 to your computer and use it in GitHub Desktop.
Save felixhummel/ee15c4eca9c3d17066ab30aa174d61c6 to your computer and use it in GitHub Desktop.
postgres json --> array --> pgvector
postgres=# CREATE TABLE x AS SELECT '{"foo": 1, "bar": 2}'::jsonb AS payload;
SELECT 1
postgres=# SELECT * FROM x;
payload
----------------------
{"bar": 2, "foo": 1}
(1 row)
postgres=# SELECT ARRAY[payload->'foo', payload->'bar']::float[]::vector FROM x;
array
-------
[1,2]
(1 row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment