Are PostgreSQL column names case-sensitive?

前端 未结 3 1653
天涯浪人
天涯浪人 2020-11-21 05:46

I have a db table say, persons in Postgres handed down by another team that has a column name say, \"first_Name\". Now am trying to use PG commande

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-21 06:15

    To quote the documentation:

    Key words and unquoted identifiers are case insensitive. Therefore:

    UPDATE MY_TABLE SET A = 5;
    

    can equivalently be written as:

    uPDaTE my_TabLE SeT a = 5;
    

    You could also write it using quoted identifiers:

    UPDATE "my_table" SET "a" = 5;
    

    Quoting an identifier makes it case-sensitive, whereas unquoted names are always folded to lower case (unlike the SQL standard where unquoted names are folded to upper case). For example, the identifiers FOO, foo, and "foo" are considered the same by PostgreSQL, but "Foo" and "FOO" are different from these three and each other.

    If you want to write portable applications you are advised to always quote a particular name or never quote it.

提交回复
热议问题