sql-psi
sql-psi copied to clipboard
EmbeddedSQL: Support SET variable = expr
Before merging: Please merge https://github.com/AlecStrong/sql-psi/pull/433 first because it contains a commit of it
SET ? = 42;
SET ?, ? = ABS(42), 42;
SET ?, ? = SELECT first_name, last_name FROM hockey_player WHERE _id = ?;
just want to make sure I understand the actual SQL going on before reviewing these PRs:
in this case, the ?
is not a bound parameter, but a variable being used in future sql statements?
Yes, they are host variables. For embeddedSQL you need a precompiler which has access to the host variables and bind these variables into the sql query and write the result into the host variables.
What do you think about a new rule hostvariables ::= ':' string
? Would be needed in SELECT INTO
too.
Added the host variable rule, nice idea! Works also better with sqldelight class generating
SET :FOO, :BAR = ABS(?), :A;
should this still be open as well?
if yes, is sql-psi the right place for it? I assume this isn't ANSI SQL we would want to pass compilation for like SQLite
good question. It is part of the sql standard, but is optional and only available if you have a pre-compiler. And sqlite does not support this precompiler too. Then we should also revert #420
I see, the fact that its part of the standard but is optional make this difficult. I would opt to not have them in but its because they're very unusual to me which isn't a good reason
Personally, I think the reason to remove this syntax from sql-psi is okay cause it is very uncommon. Let's create a ticket if somebody else wants this feature too. In the meantime, I will implement this syntax in my db2 dialect.