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

Add interpolated variables #744

Open
mcamou opened this issue Dec 15, 2020 · 4 comments
Open

Add interpolated variables #744

mcamou opened this issue Dec 15, 2020 · 4 comments
Labels
feature request New issue opened using "Feature request" template

Comments

@mcamou
Copy link

mcamou commented Dec 15, 2020

Is your feature request related to a problem? Please describe.
No

Describe the solution you'd like

It would be great to have the possibility of having interpolated values in the query editor, which you could somehow assign (via a pull-down? That would be awesome). In my case, we have a DB with similarly-named tables which differ in the prefix, and I sometimes do queries like such as this (this is a very simplified version):

SELECT * FROM foo_abc WHERE x NOT IN (SELECT x FROM foo_def);

It would be really great to be able to do something like:

-- @var prefix=foo
SELECT * FROM #prefix#_abc WHERE x NOT IN (SELECT x FROM foo_def);

and if #prefix# is not defined in the file, you could pop up a dialog (or, if you want to be really fancy, you could somehow define it as a list, and the dialog could put up a pull-down list)

This would be just text interpolation, nothing smart like adding quotes where needed.

Describe alternatives you've considered

What I usually do is select the whole set of queries and search/replace.

Additional context

@mcamou mcamou added the feature request New issue opened using "Feature request" template label Dec 15, 2020
@jessereitz
Copy link

@mcamou FYI this is already implemented with sqltools.queryParams.enableReplace and sqltools.queryParams.regex, it's just not very well documented

lucasvieirasilva added a commit to lucasvieirasilva/vscode-sqltools that referenced this issue Dec 12, 2022
gjsjohnmurray added a commit that referenced this issue Dec 22, 2022
* [#744] Support for Interpolated Variables

* Update extension.ts

* Apply suggestions from code review

Co-authored-by: John Murray <johnm@georgejames.com>

Co-authored-by: John Murray <johnm@georgejames.com>
@gjsjohnmurray
Copy link
Collaborator

PR #1064 from @lucasvieirasilva has implemented this. It is in today's 0.27.0 release.

@diego-vicente
Copy link

Hi! Just came accross this issue, and regarding what @mcamou said:

It would be really great to be able to do something like:

-- @var prefix=foo
SELECT * FROM #prefix#_abc WHERE x NOT IN (SELECT x FROM foo_def);

Is that actually implemented but not documented? Or are the interpolated variables only to be used from the connection settings?

@gjsjohnmurray
Copy link
Collaborator

@diego-vicente AFAIK you can currently only pre-define variable values in the connection definition, not in comments above the query.

@gjsjohnmurray gjsjohnmurray reopened this Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New issue opened using "Feature request" template
Projects
None yet
Development

No branches or pull requests

4 participants