From: ankane (@ankane) <noreply+ankane@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] issue #963: Question: Binary initialisation
Date: Fri, 06 Mar 2026 03:29:57 +0000
Message-ID: <gh-pgvector-pgvector-963-c4009304277@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-963@github.com>
References: <gh-pgvector-pgvector-963@github.com>
Ah, gotcha. You can currently create a custom function for it:
```sql
CREATE FUNCTION sparsevec_from_arrays(indices int[], value float4[], dimensions int) RETURNS sparsevec AS $$
SELECT ('{' || (SELECT string_agg(indices[i] || ':' || value[i], ',') FROM generate_series(1, array_length(indices, 1)) i) || '}/' || dimensions)::sparsevec;
$$ LANGUAGE SQL IMMUTABLE STRICT PARALLEL SAFE;
```
```sql
SELECT sparsevec_from_arrays('{1,3,5}', '{2,4,6}', 6);
```
Can you share more about the use case, and why it's important to have the functionality in the database vs. the client libraries?