Domains in PostgreSQL projects

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.

PostgreSQL domain - other object

Specify name, description, and other properties for your newly created domain in the right-side panel.

PostgreSQL domain - definition

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:

PostgreSQL domain

Generated SQL script for PostgreSQL table with a column where the domain is used:

SQL script

#

Copyright: 2020 Datensen. All rights reserved.
This website uses cookies to ensure you get the best experience on our website.