7

The interactive SQL explorer interface for https://data.stackexchange.com/ has a convenient feature where you can request user input in a text field using syntax like ##variable##. But the interpolated value of ##variable## doesn't seem to have a facility for including it in strings.

For example, in a search like https://data.stackexchange.com/stackoverflow/query/1357825/posts-containing-keyword-in-title I can type in

couldn''t resolve host

to get ##keyword## in ... where Title like '%##keyword##%' to search for "couldn't resolve host", but notice how I needed to (understand what's wrong with unescaped single quotes, and) double the single quote in the search phrase to escape it.

The help section says I can type parameters as :int or :string and with that, I expected

... where Title like '%##keyword:string##%'

to do what I wanted, but it definitely doesn't.

Is there a way to get single quotes in the value escaped for me, to make the search easier to share with people who do not understand SQL or even necessarily what "escaping" means?

8

SEDE Parameters are plain text replacements.

Adding a type either adds client-side validation (for int) or wraps your value in 'quotes'. There is no magic.

To get your example query to work you have to concat the string and then use the string type on the parameter.

select Id as [Post Link], Body, Score from Posts
where Title like concat('%', ##keyword:string##, '%') and ParentId is null;

And see it in action

query with LIke concat and keyword "couldn't resolve host" and a few results

See also How can I parametrize a query with a database name on the SEDE?

Keep in mind SEDE is updated once a week on Sunday.
Use the awesome SEDE Tutorial written by the unforgettable Monica Cellio.
Say "Hi" in SEDE chat.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .