PostgreSQL 中的函数名称是否不区分大小写? [英] Are function names in PostgreSQL case insensitive?

查看:52
本文介绍了PostgreSQL 中的函数名称是否不区分大小写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 PostgreSQL 中定义或调用函数时,大小写是否重要?

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

推荐答案

函数名是标识符(如表名、字段名),同关于区分大小写的规则适用于所有人.

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.

这篇关于PostgreSQL 中的函数名称是否不区分大小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆