Skip to main content
2 of 12
add more links, typos
Erwin Brandstetter
  • 182.2k
  • 28
  • 457
  • 620

No. No gain at all. The manual explicitly states:

Tip: There is no performance difference among these three types, apart from increased storage space when using the blank-padded type, and a few extra CPU cycles to check the length when storing into a length-constrained column. While character(n) has performance advantages in some other database systems, there is no such advantage in PostgreSQL; in fact character(n) is usually the slowest of the three because of its additional storage costs. In most situations text or character varying should be used instead.

char(n) is a largely outdated, useless type. Stick with varchar(n). If you don't need to enforce the length, varchar or text would be a tiny bit faster. You won't be able to measure a difference.

Also, if all strings are exactly 36 characters in length, there is no storage saving either way, not even a minuscule one. Both have exactly the same size on disk and in RAM. You can test with pg_column_size() (on an expression and on a table column).

Related:

You didn't ask for other options, but I'll mention two:

Extensive benchmark comparing (among other) the effect of COLLATE "C" on performance:

  • Slow query ordering by a column in a joined table

  • UUID, obviously. Your string suspiciously looks like a UUID (32 hex digits plus 4 delimiters). It would be much more effective to store these as actual uuid data type, which is faster in multiple ways and only occupies 16 bytes (as opposed to 37 bytes for either char(36) or varchar(36). COLLATION would be irrelevant, too.

      SELECT '922475bb-ad93-43ee-9487-d2671b886479'::uuid
    
Erwin Brandstetter
  • 182.2k
  • 28
  • 457
  • 620