How to use constants in SQL CREATE TABLE?

I have 3 SQL tables that are defined as follows:

CREATE TABLE organs( abbreviation VARCHAR(16), -- ... other stuff ); CREATE TABLE blocks( abbreviation VARCHAR(16), -- ... other stuff ); CREATE TABLE slides( title VARCHAR(16), -- ... other stuff ); 

The 3 fields primarily use VARCHAR (16) because they are connected and have the same length limit.

Is there a (preferably portable) way to put '16' in a constant / variable and a link that is instead in a CREATE TABLE? eg. something like this would be nice:

  CREATE TABLE slides( title VARCHAR(MAX_TITLE_LENGTH), -- ... other stuff ); 

I am using PostgreSQL 8.4.

+4
source share
1 answer

What for domain:

  CREATE DOMAIN title_data AS varchar (16);
 CREATE TABLE slides (
     title title_data,
     - ... other stuff
  );
+7
source

Source: https://habr.com/ru/post/1333922/


All Articles