I don't think it's always been like this, as the same queries work under 6.x. An example of this failing is the following:

This fails:
db_query('SELECT nid FROM {node} WHERE type = "article"');

This works:
db_query('SELECT nid FROM {node} WHERE type = \'article\'');

Is this a bug or just undocumented? I would think that double quotes should still be allowed...

Comments

floretan’s picture

This came up as an issue for a few tests who were using that synthax. Most of core uses double quotes around queries where string parameters are used:

  db_query("SELECT nid FROM {node} WHERE type = 'article'");
Susurrus’s picture

Should that be the case? It is my understanding that pgSQL doesn't support double-quotes for surrounding strings, though that shouldn't be an issue once DB: TNG gets in (assuming it does).

So as of right now it seems like this is still a bug or issue that is undocumented. What is the proper solution to this problem? document or fix?

damien tournoud’s picture

Status: Active » Closed (works as designed)

In fact the SQL standard define a string literal as

<character string literal> ::=
              [ <introducer><character set specification> ]
              <quote> [ <character representation>... ] <quote>

and the quote as

<quote> ::= '

(SQL-92 standard pages 80 and 89)

So the double quote is not legal in standard SQL.

The current behavior of db_query() is thus perfectly correct. Marking as by design.