Are function names in PostgreSQL case insensitive?

前端 未结 3 1406
北荒
北荒 2020-12-11 06:03

Does case matter at all when you define or call a function in PostgreSQL?

3条回答
  •  佛祖请我去吃肉
    2020-12-11 06:45

    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.
    

提交回复
热议问题