Is it possible to escape a SQL identifier in either MySQL or BigQuery or any other RDBMS that allows quoting of identifiers with the `
character? For example:
select 1 as `select`
Works, but then How would I add a literal backtick to it, or is that just not allowed?
select 1 as `sel`ect`
Advertisement
Answer
Yes. Use a doubled backtick, eg:
create table `my``table` (`my``id` int);
This is similar syntax for including quotes in text, eg 'O''Leary'
See live demo of
create table `my``table` (`my``id` int); insert into `my``table` (`my``id`) values (1); select * from `my``table`;
outputs:
my`id |
---|
1 |
By the way, the documentation says any UTF-8 character (except U+0000
) is allowed in a back tick quoted identifier.