Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are function names in PostgreSQL case insensitive?

Tags:

postgresql

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

like image 954
dan Avatar asked Jun 10 '11 19:06

dan


People also ask

Are Postgres functions case sensitive?

Oracle names aren't case sensitive. PostgreSQL names are case sensitive. By default, AWS SCT uses object name in lower-case for PostgreSQL. In most cases, you'll want to use AWS DMS transformations to change schema, table, and column names to lower case.

Are function names case sensitive?

Note: Function names are case-insensitive, though it is usually good form to call functions as they appear in their declaration.

How do I make a case-insensitive in PostgreSQL?

While using regular expressions, we need to use the PostgreSQL ~* operator instead of the like operator; we can also use the ilike operator in PostgreSQL. We can also create an extension name as citext to use the case insensitive query in PostgreSQL; we need to create it first to use the extension of citext.

Are column names case sensitive in Postgres?

So, yes, PostgreSQL column names are case-sensitive (when double-quoted): SELECT * FROM persons WHERE "first_Name" = 'xyz'; Read the manual on identifiers here. My standing advice is to use legal, lower-case names exclusively so double-quoting is not needed.


2 Answers

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.
like image 98
leonbloy Avatar answered Sep 24 '22 08:09

leonbloy


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.

like image 28
Peter Eisentraut Avatar answered Sep 22 '22 08:09

Peter Eisentraut