You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "leoyvens (via GitHub)" <gi...@apache.org> on 2024/11/26 16:50:28 UTC

[I] Document PREPARE statements [datafusion]

leoyvens opened a new issue, #13570:
URL: https://github.com/apache/datafusion/issues/13570

   DataFusion supports `PREPARE` statements, with flavors to suite all tastes such as explicit or inferred types, and positional or named arguments. I noticed docs for this feature are entirely missing from the SQL Reference ([link](https://datafusion.apache.org/user-guide/sql/index.html)).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Document PREPARE statements [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on issue #13570:
URL: https://github.com/apache/datafusion/issues/13570#issuecomment-2503560227

   Yes, thank you @leoyvens 
   
   @NGA-TRAN , @erratic-pattern and @jonahgao  have done some great work in this area and indeed it would be great to get it documented


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Document PREPARE statements [datafusion]

Posted by "dhegberg (via GitHub)" <gi...@apache.org>.
dhegberg commented on issue #13570:
URL: https://github.com/apache/datafusion/issues/13570#issuecomment-2647102910

   I've started to put together some basic documentation for prepared statements, but when generating examples I'm struggling to use named parameters.
   
   Using `SessionContext::sql()` for example will hit  [this](https://github.com/apache/datafusion/blob/603721d38ef9f187deaf76664e7b1679e44a90cd/datafusion/sql/src/expr/value.rs#L124) validation ensuring a `$1` style placeholder is used rather than `:name`.
   
   Creating a logical plan from the SQL string has a similar issue, preventing the user from later calling `replace_params_with_values`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Document PREPARE statements [datafusion]

Posted by "jonahgao (via GitHub)" <gi...@apache.org>.
jonahgao commented on issue #13570:
URL: https://github.com/apache/datafusion/issues/13570#issuecomment-2648055675

   > I've started to put together some basic documentation for prepared statements, but when generating examples I'm struggling to use named parameters.
   > 
   > Using `SessionContext::sql()` for example will hit [this](https://github.com/apache/datafusion/blob/603721d38ef9f187deaf76664e7b1679e44a90cd/datafusion/sql/src/expr/value.rs#L124) validation ensuring a `$1` style placeholder is used rather than `:name`.
   > 
   > Creating a logical plan from the SQL string has a similar issue, preventing the user from later calling `replace_params_with_values`.
   
   I think it should be supported because this [test](https://github.com/apache/datafusion/blob/17396a530f9178903e007f364148cd79242b7a43/datafusion/core/tests/sql/select.rs#L54) can be passed.
   
   But it seems that we can't EXECUTE it by SQL.
   ```sh
   DataFusion CLI v45.0.0
   > prepare p1 as select $foo;
   0 row(s) fetched.
   Elapsed 0.003 seconds.
   
   > execute p1(foo := 1);  🤔 Invalid statement: sql parser error: Expected: ), found: := at Line: 1, Column: 16
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Document PREPARE statements [datafusion]

Posted by "dhegberg (via GitHub)" <gi...@apache.org>.
dhegberg commented on issue #13570:
URL: https://github.com/apache/datafusion/issues/13570#issuecomment-2648541644

   I think I'll post my documentation change without the named arguments.  I'll then take a stab as adding support for named arguments with EXECUTE.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Document PREPARE statements [datafusion]

Posted by "dhegberg (via GitHub)" <gi...@apache.org>.
dhegberg commented on issue #13570:
URL: https://github.com/apache/datafusion/issues/13570#issuecomment-2667446243

   I was looking at how to support named parameters for PREPARE statements.
   
   I expected the supported syntax in SQL dialects to looks something like:
   
   ```
   PREPARE function_name AS SELECT * FROM example WHERE column_a > :a_param AND column_b < :b_param"
   ```
   
   ```
   EXECUTE function_name USING :a_param = 10, :b_param = 20.5
   ```
   
   That sort of syntax does not seem to be present in most dialects, with a few exceptions (like [sqlite](https://www.sqlite.org/c3ref/bind_blob.html))
   
   What is the expected behavior / syntax we're look for with named parameters in the context of a prepared statement?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Document PREPARE statements [datafusion]

Posted by "dhegberg (via GitHub)" <gi...@apache.org>.
dhegberg commented on issue #13570:
URL: https://github.com/apache/datafusion/issues/13570#issuecomment-2648544296

   take


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Document PREPARE statements [datafusion]

Posted by "jonahgao (via GitHub)" <gi...@apache.org>.
jonahgao commented on issue #13570:
URL: https://github.com/apache/datafusion/issues/13570#issuecomment-2668747633

   Maybe we can follow DuckDB's syntax; it seems quite readable to me.
   
   https://duckdb.org/docs/sql/query_syntax/prepared_statements.html#named-parameters-parameter
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Document PREPARE statements [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on issue #13570:
URL: https://github.com/apache/datafusion/issues/13570#issuecomment-2647797989

   Thanks @dhegberg  -- I am not sure if that is desired or not -- maybe it is worth a ticket


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org