开发者

Are function names in PostgreSQL case insensitive?

Does case matter at all when you define or call a function in Pos开发者_C百科tgreSQL?


Function names are identifiers (like table names, field names), the same rules about case sensitivy apply to all.

In short, identifiers are case insensitive, unless quoted.

More precisely, an unquoted identifier is internally converted to lowercase and then a case sentitive match is attempted. This can make your life miserable (i.e hidden bugs, hours wasted), typically if you used quoted identifiers when defining the table or function.

That's why you should always define your own naming convention and stick to it.

General advice: use always lowercase for identifiers, and be happy.

db=# select now();
              now
-------------------------------
 2011-06-10 16:33:06.588401-03
(1 row)

db=# select Now();
              now
-------------------------------
 2011-06-10 16:33:08.066818-03
(1 row)

db=# select "now"();
              now
-------------------------------
 2011-06-10 16:33:14.543381-03
(1 row)

db=# select "Now"();
ERROR:  function Now() does not exist
LINE 1: select "Now"();
               ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.


I suppose you can get lots of varying answers to this question. Technically, function names in PostgreSQL are case sensitive. But when you address a function through SQL, identifier syntax rules apply, namely that unquoted identifiers are folded to lower case. This can give the illusion of case insensitive function names, but it's only the idiosyncrasy of the SQL language. Contrast this, for example, with names of procedural languages, which are case insensitive even if you double quote the identifiers.


Identifier and key word names in PostgreSQL are case insensitive. Function names are identifiers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜