Pages

Monday, April 13, 2026

How to Use a PostgreSQL Generated Column for a Formatted Virtual Server SKU / Flavor

When designing a service catalog or virtual server definition table in PostgreSQL, it is common to need a derived attribute that is automatically generated from several existing columns.

A practical example is a virtual server flavor code (SKU - Stock Keeping Unit) derived from these attributes:

  • vserver_type – values such as ECONOMY, STANDARD, PREMIUM
  • num_of_vcpu – number of vCPUs, for example 1 to 64
  • capacity_of_vram – RAM size, for example 1 to 128

The requirement is to automatically generate a formatted code such as:

ECONOMY-04-016

In this format:

  • vserver_type is converted to uppercase
  • num_of_vcpu is formatted to 2 digits
  • capacity_of_vram is formatted to 3 digits
  • the delimiter is a hyphen (-)