Domains in PostgreSQL projects
Note: this page is outdated. Please visit the latest article Domains in PostgreSQL projects
Domains
Domains can be defined in a similar way as Enums (enumerated types). In the main menu, click Others and select Domain. Then click the diagram area and add a new graphical object to the canvas.
Specify name, description, and other properties for your newly created domain in the right-side panel.
What are the key advantages of using domains in PostgreSQL?
You can use standard datatypes in your column definitions, however, in case you need to change the datatype, you will have to modify it everywhere. If you used domains, such a change would be required only in the domain definition. Also, you can specify a check constraint for your domain. The same check constraint will be applied to every column where the domain will be used instead of the standard data type. Domains are great time-savers.
Domain selected instead of the standard data type:
Generated SQL script for PostgreSQL table with a column where the domain is used:
#