Hello,
I was bitten by a length-truncated role name used in a script since the truncation only raises a NOTICE. The symptom
wasthat the some GRANTs ended up on the wrong objects after name truncation.
Then, I experimented with tables with long names and was surprised by the truncation behavior:
test=# create table longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong(a int);
NOTICE: identifier "longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong" will be truncated to
"longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglon"
CREATE TABLE
test=# \d longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong
Did not find any relation named "longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong".
test=# drop table longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglongNOT; --SURPRISE!
NOTICE: identifier "longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglongnot" will be truncated to
"longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglon"
DROP TABLE
One really has to pay attention to the length limits (63 bytes):
1) Name truncation is not an error.
2) psql \d doesn't work with long names- perhaps the same auto-truncation rules should apply?
3) DROPping a non-existent table with a truncated identifier unintentionally drops the long name table.
For those curious, I hit the limits prefixing roles with UUIDs for automated testing so that database-global objects
canbe deleted after the test.
I wish there were a way to turn the truncation into an error. Is there some better way I could have caught this?
Cheers,
M