What is the difference between single quotes and double quotes in PostgreSQL?

前端 未结 3 1915
终归单人心
终归单人心 2020-11-27 05:15

I am new to PostgresSQL.I tried

select * from employee where employee_name=\"elina\";

But that results error as follows:

E         


        
3条回答
  •  感动是毒
    2020-11-27 05:58

    As explained in the PostgreSQL manual:

    A string constant in SQL is an arbitrary sequence of characters bounded by single quotes ('), for example 'This is a string'. To include a single-quote character within a string constant, write two adjacent single quotes, e.g., 'Dianne''s horse'. Note that this is not the same as a double-quote character (").

    Elsewhere on the same page:

    There is a second kind of identifier: the delimited identifier or quoted identifier. It is formed by enclosing an arbitrary sequence of characters in double-quotes ("). A delimited identifier is always an identifier, never a key word. So "select" could be used to refer to a column or table named "select", whereas an unquoted select would be taken as a key word and would therefore provoke a parse error when used where a table or column name is expected.

    TL;DR: Single quotes for string constants, double quotes for table/column names.

提交回复
热议问题