Skip to content

Trouble getting set-returning-function to work #3015

Answered by weiznich
benthillerkus asked this question in Q&A
Discussion options

You must be logged in to vote
  sql_query("select * from create_user(?, ?);")
   .bind::<diesel::sql_types::Text, _>(body.name)
   .bind::<diesel::sql_types::Text, _>(private_id.to_string())
   .first(conn)

This fails because .first() expects a query that implements LimitDsl, so that it is able to apply an limit clause. That's not implemented for raw sql queries as applying an limit clause there may be not supported. Use .get_result() in this case instead.

   sql_function! {
    fn create_user(name: Text, password: Text) -> schema::users::SqlType;
  }

  let register_fn = create_user(body.name, private_id.to_string());
  select(register_fn).first::<models::User>(conn)

Unfortunately does sql_function currently not …

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@benthillerkus
Comment options

Comment options

You must be logged in to vote
1 reply
@benthillerkus
Comment options

Answer selected by benthillerkus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants