Home > Software design >  Can a backticked identifier have a backtick in it?
Can a backticked identifier have a backtick in it?

Time:08-14

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`

CodePudding user response:

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.

  • Related