Sqlx (postgresql) error when psql runs fine

I am trying to run a query with a join and the query seems to run fine (no error) in psql, but when the exact same query is entered into sqlx::query! is fails. What am I doing wrong and where?

SELECT * from nodes JOIN users on users.user_id = nodes.user_id;


match sqlx::query!("SELECT * from nodes JOIN users on users.user_id = nodes.user_id;")
                Ok(a) => {}
                Err(e) => {}

error[E0124]: field `user_id` is already declared

That probably returns 2 columns named user_id in psql (one from the nodes table, one from the users table).
sqlx tries to use the same name for both and thus fails.
You will need to make it more explicit, e.g. by using nodes.* to get only columns from nodes or by listing out exactly the columns you want.

That was it. Thank you!!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.