Skip to content
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

Variable substitution tokens incompatible with PostgreSQL #1

Open
Fresa opened this issue Jul 31, 2017 · 2 comments
Open

Variable substitution tokens incompatible with PostgreSQL #1

Fresa opened this issue Jul 31, 2017 · 2 comments

Comments

@Fresa
Copy link

Fresa commented Jul 31, 2017

$variablename$ is used by PostgreSQL as dollar quoting: https://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-DOLLAR-QUOTING

It would be nice to be able to decide which token to use, or completely swap out the VariableSubstitutionPreprocessor.

@AdrianJSClark
Copy link
Member

There isn't a straightforward seam around the variable substitution code to make that change. However, I've got two ways forward that will work within the current framework. One is a work-around and one is a quick summary of what the fix would be.

Unfortunately I'm a bit time-poor at the moment, and am not particularly familiar with PostgreSQL, so can't implement either in full myself.

The Work Around

  1. Create a PostgreSQL-specific variable preprocessor by inheriting from VariableSubstitutionSqlParser and specifying your own delimiter characters.
  2. Create your own implementation of IScriptPreprocessor based on the existing VariableSubstitutionPreprocessor code with the important change of using your custom subclass of VariableSubstitutionSqlParser from the first step.
  3. Disable the built-in variable substitution pre-processor by calling .WithVariablesDisabled() at configuration time.
  4. Add your custom script preprocessor to your database upgrader using the .WithPreprocessor(...) extension method during configuration.

The Proper Fix

  1. Create a PostgreSQL-specific variable preprocessor by inheriting from VariableSubstitutionSqlParser and specifying appropriate delimiter characters.
  2. Create a PostgreSQL implementation of IScriptPreprocessor based on the existing VariableSubstitutionPreprocessor code with the important change of using the custom subclass of VariableSubstitutionSqlParser from the first step.
  3. Copy and modify SqlScriptExecutor so that it creates the customised PostgreSQL variable substitution preprocessor at the appropriate time.
  4. Update all configuration extension methods for PostgreSQL to wire-in the replacement, specialised SqlScriptExecutor.

@droyad
Copy link
Member

droyad commented Dec 10, 2024

Also see linked issues for more use cases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Wishlist
Development

No branches or pull requests

4 participants