MySQL是否支持用户定义的数据类型

时间:2022-03-23 15:52:50

Is it possible to define (alias) a base data type in MySQL?

是否可以在MySQL中定义(别名)基本数据类型?

Currently I would like to define UUID as char(32), and then use UUID as the type throughout the schema definition. As we're prototyping at the moment, UUID is very likely to change - I'd like to ensure that this change is reflected consistently throughout the schema.

目前我想将UU​​ID定义为char(32),然后在整个模式定义中使用UUID作为类型。由于我们目前正在进行原型设计,UUID很可能会发生变化 - 我希望确保在整个架构中始终如一地反映这一变化。

I'm thinking something like:

我想的是:

alias type UUID char(32);

别名类型UUID char(32);

Thanks in advance!

提前致谢!

2 个解决方案

#1


8  

In this case a text preprocesor like M4 or any C-language preprocesor may be useful.

在这种情况下,像M4或任何C语言预处理器的文本预处理器可能是有用的。

If you have the following in file tables.sql:

如果文件tables.sql中有以下内容:

define(UUID, char(32))
create table mytable1 (my_uuid UUID);
create table mytable2 (my_uuid UUID);

Running

运行

$ m4 tables.sql

you'll get:

你会得到:

create table mytable1 (my_uuid char(32));
create table mytable2 (my_uuid char(32));

#2


0  

well ENUM does the work until certain expectation of your custom data types, but i'm too hoping to look forward to this topic

ENUM做了一些工作,直到你的自定义数据类型的某些期望,但我也希望期待这个主题

#1


8  

In this case a text preprocesor like M4 or any C-language preprocesor may be useful.

在这种情况下,像M4或任何C语言预处理器的文本预处理器可能是有用的。

If you have the following in file tables.sql:

如果文件tables.sql中有以下内容:

define(UUID, char(32))
create table mytable1 (my_uuid UUID);
create table mytable2 (my_uuid UUID);

Running

运行

$ m4 tables.sql

you'll get:

你会得到:

create table mytable1 (my_uuid char(32));
create table mytable2 (my_uuid char(32));

#2


0  

well ENUM does the work until certain expectation of your custom data types, but i'm too hoping to look forward to this topic

ENUM做了一些工作,直到你的自定义数据类型的某些期望,但我也希望期待这个主题