pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
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?

view thread (9+ messages)  latest in thread

Message-ID: <gh-pgvector-pgvector-963-c4009304277@github.com>
Permalink:  ../gh-pgvector-pgvector-963-c4009304277@github.com/

 · 


This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox