Set column name alias from a parameter?

I could not find any discussion of this topic, so here's my question.

I know I can set the column heading with the AS keyword. The values that I can set seem to be limited to literals from the Cypher code, though the syntax does not require quotes. (In fact, since it doesn't allow quotes, I can't have column names with spaces, leading numbers don't work, etc.). So I can do this:

... return s.Value as NewYork ...

but not:

... return s.Value as 'New York' ...

Is there any way to set the AS column name to the value of a parameter? I do not see how, because the AS value is taken literally, not resolved. I would like to do this and have the column heading come out as whatever city was provided. In other words, a more parameterized report output format:

with 'New York' as location ...
some logic that provides values for rows where some attribute is New York
... return s.Value as location ...

Currently, I have to show the attribute value as another column, which takes up space.

... return s.City as Location, s.Value as Value...

If the column heading could be parameterized, it would be clear that the whole report relates to New York values, saving a column. (In my real case, multiple columns because it's a comparison report.)

Hi @rsworden59

Characters containing spaces in the title can be displayed by enclosing them with backticks.

` is backtick. it's not a single quote.

Thanks, now I see that the column aliases follow the rules in "Naming rules and recommendations: This section describes rules and recommendations for the naming of node labels, relationship types, property names, variables, indexes, and constraints."

I had not thought of the AS clause as actually creating a new name which can be passed on as a name, I was thinking of it as a final result that was just text, but that's not always true. So it makes sense that they need to follow name rules.

Then I learned about parameters, symbols starting with $, which will make my code more reusable. They work in node label expressions, and they work in WHERE predicates, but they don't work in AS clauses. This fails with "expected an identifier":

match (s:Site) where s.name = $theSite return s.name as $theSite

So I'm still looking for a way to make the resulting column header a variable string.

Hi @rsworden59

I don't think it is possible to write AS as a variable.
However, it is possible to create "AS variables" by programming languages such as Python.