Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If it's useful to use the same string literal character "as everyone else", it would be useful to use the same as a language you are very likely to see combined - so, single quote.

On the other hand, if it's useful to have minimum need of escaping, then single quote is still better, because in SQL it's much more common to quote identifier names than to have literal strings.

  query = 'SELECT "columnA" FROM "aTable" WHERE "columnB" = \'foo\';'
compared to

  query = "SELECT \"columnA\" FROM \"aTable\" WHERE \"columnB\" = 'foo';"


> it would be useful to use the same as a language you are very likely to see combined - so, single quote.

Why? It’s obvious that it causes issues as I showed, and yet you simplay claim the opposite without argument? The difference between other programming languages and SQL is, of course, that it’s very common to have embedded SQL code in your program, but not common to have embedded strings of code in another programming language.

> in SQL it's much more common to quote identifier names than to have literal strings.

That is certainly not true. The kind of SQL you quote is only found in auto-generated SQL by ORMs and the like, and those are not likely to exist as strings in code. To use your example, this is the normal SQL way to write that:

  query = "SELECT columnA FROM aTable WHERE columnB = 'foo';"
I.e. no double quotes needed; no need to escape anything.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: