Strange behaviour in Postgresql

Your update_tbl_point function is probably doing something like this:

new.last_update = current_timestamp;

but it should be using new."Last_Update" so fix your trigger function.

Column names are normalized to lower case in PostgreSQL (the opposite of what the SQL standard says mind you) but identifiers that are double quoted maintain their case:

Quoting an identifier also makes it case-sensitive, whereas unquoted names are always folded to lower 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. (The folding of unquoted names to lower case in PostgreSQL is incompatible with the SQL standard, which says that unquoted names should be folded to upper case. Thus, foo should be equivalent to “FOO” not “foo” according to the standard. If you want to write portable applications you are advised to always quote a particular name or never quote it.)

So, if you do this:

create table pancakes (
    Eggs integer not null
)

then you can do any of these:

update pancakes set eggs = 11;
update pancakes set Eggs = 11;
update pancakes set EGGS = 11;

and it will work because all three forms are normalized to eggs. However, if you do this:

create table pancakes (
    "Eggs" integer not null
)

then you can do this:

update pancakes set "Eggs" = 11;

but not this:

update pancakes set eggs = 11;

The usual practice with PostgreSQL is to use lower case identifiers everywhere so that you don’t have to worry about it. I’d recommend the same naming scheme in other databases as well, having to quote everything just leaves you with a mess of double quotes (standard), backticks (MySQL), and brackets (SQL Server) in your SQL and that won’t make you any friends.

Leave a Comment