0

I have a char(13) column named a in table test.

I created a classic before insert function with the following line :

raise notice 'a: -->%<-- len = %', new.a, length(new.a);

When I run insert into test (a) values('1');, I get the following output :

a: -->1            <-- len = 1

Strange, no ?

Fred Sullet
  • 371
  • 1
  • 6
  • 18

1 Answers1

0

No, not strange at all. char is a blank padded data type. So if you assign '1' to your column, it is actually stored as '1 '.

The solution is simple: don't use char(n)

  • actually the value is not assigned yet because we are in a BEFORE INSERT trigger function, is it ? – Fred Sullet Aug 13 '20 at 16:05
  • It is assigned to the field in the record to be inserted. Just don't use `char()` regardless of this problem. –  Aug 13 '20 at 16:11