Expand my Community achievements bar.

How to escape semicolon in a string literal in queries

Avatar

Level 3

Hi 

This seems like a pretty stupid question, but I am stumped.

I am writing some queries in Adobe Experience Platform, and I want to use a string literal in a SELECT, which includes a semicolon. Something like this:

 

select 'Test with a semicolon;' 

I get this error:

[Code: 0, SQL State: 42601] ERROR: line 1:8: no viable alternative at input 'select ''

It looks like the semicolon in the string literal is read as a command terminator, and anything after it is ignored, hence the syntax error.

I tried a number of ways to escape the semicolon, but nothing worked so far.

 

Any help will be really appreciated. Thanks

1 Reply

Avatar

Level 4

Agree with you! I can see in log how the ':' is breaking apart the query. I tried with the common ones and the ascii value conversion works

Ascii of semicolon: 59, hence

SELECT CONCAT('Test with a semicolon ', CHR(59)) AS output;

See if it helps!