SQL - Escaping a Parentheses Character When Setting Column Name

I’m doing the SQL CIA World Facebook project and came across this small issue. This is the step where it asks to display which countries have a higher death rate than birth rate.

This code works fine:

%%sql
  SELECT name, ROUND((birth_rate - death_rate), 2) AS net_growth_rate
    FROM facts
   WHERE death_rate > birth_rate
ORDER BY net_growth_rate;

Then I thought of setting the net_growth_rate column title to net_growth_rate(birth minus death) just to make it more clear but I got an error which I assume is due to the parentheses characters.

I tried googling how to “escape” the parentheses characters and came across suggestions like ticks, single quotes, backslashes, brackets. None of those seem to be working for me so I am assuming I am doing something wrong.

Not a huge deal by leaving it as net_growth_rate but thought I’d ask in case it comes up again.

Thanks for your time!

Using a string to define a column name

AS "net_growth_rate(birth minus death)"

OR

Using CONCAT to format the column name.

AS CONCAT('net_growth_rate', '(birth minus death)')

Why make column too difficult to reference

1 Like

Thanks for replying. Neither of those are working for me. Maybe it’s something to do with the way it’s set up in Jupyter?

But you make a great point adding the parentheses would make it more difficult to reference, I’ll leave it as is then.

Thanks again!

1 Like