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

Feature Request - var interpolation inside of query() #1109

Open
markhuge opened this issue Jan 5, 2017 · 3 comments
Open

Feature Request - var interpolation inside of query() #1109

markhuge opened this issue Jan 5, 2017 · 3 comments

Comments

@markhuge
Copy link

markhuge commented Jan 5, 2017

When creating a template, it'd be really handy to be able to pass in a relevant string that varies between tasks vs having to pass the entire query into the var

var thingName string
var crit lambda

batch
    |query('''
       SELECT mean("value")
       FROM "myDB"."autogen".foo
       WHERE "thing" = {{ thingName }}
    ''')
    ...
   |alert()
     .crit(crit)
   ...
@rossmcdonald
Copy link
Contributor

@markhuge I believe you should be able to do this already with string concatenation:

var thingName string
var crit lambda

batch
   |query('SELECT mean("value") FROM "myDB"."autogen".foo WHERE "thing" = ' + thingName)
    ...
   |alert()
     .crit(crit)
   ...

But I agree that being able to use templated variable names would be the best solution.

@markhuge
Copy link
Author

markhuge commented Jan 6, 2017

@rossmcdonald Just FYI, the string concatenation does expand the variable, but it's not evaluated by the query. It looks like it needs to be wrapped in escaped single quotes to work:

|query('SELECT mean("value") FROM "myDB"."autogen".foo WHERE "thing" = \'' + thingName + '\'')

@rossmcdonald
Copy link
Contributor

Ah, yes, you will also need to include quotes around any literals. Thanks for letting me know.

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

No branches or pull requests

2 participants