Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can a backticked identifier have a backtick in it?

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`

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading