New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Updating Individual Array Elements #1681

Open
philip-alldredge opened this Issue May 4, 2018 · 6 comments

Comments

Projects
None yet
3 participants
@philip-alldredge

philip-alldredge commented May 4, 2018

Problem Description

As far as I am aware, Diesel does not provide a mechanism for referencing individual array elements inside of the SQL queries.

What are you trying to accomplish?

Updating a single element in an array column when working with a Postgres database. I'd like to generate a query like:

UPDATE table_with_array
SET my_array[2] = 5.0;

Using syntax like:
update(table_with_array.set(my_array.index(1).eq(5.0)).execute(db_connection);

@sgrif sgrif added the enhancement label May 4, 2018

@sgrif

This comment has been minimized.

Member

sgrif commented May 4, 2018

This is a reasonable feature request, but isn't likely to get added in the near future. I'd recommend using sql_query for this.

@philip-alldredge

This comment has been minimized.

philip-alldredge commented May 4, 2018

Okay. Thanks! It's only a minor inconvenience. Everything else works great.

@sgrif

This comment has been minimized.

Member

sgrif commented May 4, 2018

Glad to hear it. 😄

@sgrif

This comment has been minimized.

Member

sgrif commented May 4, 2018

I actually don't think this would be super hard to implement if someone were interested in tackling it (being able to select a single element of an array would be a good first step). I think this might make sense as an issue for @galuhsahid or @yamishi13 in a few weeks.

@weiznich

This comment has been minimized.

Contributor

weiznich commented May 4, 2018

Just to write it somewhere:
I think this should be done in a similar manner like the implementation of numeric operations in diesel for various types. This means in detail that instead of providing a index method we should use the Index trait from the std-lib and then return a custom wrapper for codegen from there. (Just like for Add for example)

@sgrif

This comment has been minimized.

Member

sgrif commented May 4, 2018

@weiznich We cannot safely implement Index for this due to its signature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment