- When should you use the character ' in PHP pg queries?
- When should you use the character " in PHP pg queries?
This question is based on this answer.
This question is based on this answer.
String literals in Postgres are defined using single quotes. Double quotes are used around identifiers. So the following query is valid.
SELECT "id", "name" FROM my_table WHERE "name" = 'Brian'
However, judging by the answer that you linked to, you're asking about single quote ' vs double quote " in PHP strings, rather than postgres queries.
The same as normal strings, a string in double quotes will interpolate variables, while a string in single quotes will have exactly what you put in.
$my_var = "noob";
echo "This is a test string, $my_var\nGot it?";
>> This is a test string, noob
>> Got it?
echo 'This is a test string, $my_var\nGot it?';
>> This is a test string, $my_var\nGot it?
Into a PostgreSQL query, you must use '
When you build a query in PHP, you may use ' or "
"select * from table where id = 'me'"
or
'select * from table where id = \'me\''