Is there a way to use custom data types in MySQL?

I have a database that stores (among other things) the following information:

  • Hardware Identifiers BIGINTs
  • BIGINTS storage capacity
  • VARCHARS hardware names
  • World Port Names VARCHARs

I would like to catch a more precise definition of these data types. For example, equipment identifiers do not have a numerical value, so I don’t care how they are formatted when displayed. However, storage capacities are cardinal numbers, and at the request of the user I would like to present them with thousands and decimal separators, for example. 123,456.789. Thus, I would like to clarify BIGINTin, say, ID_NUMBERand CARDINAL.

Same thing with Hardware Names, which are plain text and WWPN, which are hexadecimal, for example. 24: 68: AC: E0. So, I would like to clarify VARCHARin ENGLISH_WORDand HEXSTRING.

The specific data types that I compiled are for illustrative purposes only.

I would like to keep all this information in one place, and I wonder if anyone knows of a good way to store this in my MySQL table definitions. I could use the Comment field in the table definition, but I don't like that smell.

One approach would be to define the data structure elsewhere and use this definition to generate my CREATE TABLEs, but this will be a serious rework of the code I currently have, so I'm looking for alternatives.

? - Perl, .

+5
2

- . , , :

mysql> create table foo (id int);
Query OK, 0 rows affected (0.12 sec)

mysql> insert into foo (id) values ( 123456789);
Query OK, 1 row affected (0.00 sec)

mysql> create view v_foo as select format(id, 0) as id from foo;
Query OK, 0 rows affected (0.10 sec)

mysql> select * from v_foo;
+---------------+
| id            |
+---------------+
| 123,456,789   |
+---------------+
1 row in set (0.02 sec)

string .

+6

, .

, , , , - () , , , :

' . . .

, friedo - , - .

, , - , , , , , , - ( , , ).

, , , , , , , (, DD/MM/YY MM/DD/YY)?

, , .

EDIT: ( , ) , , , . . ( ) .

MAC- - , , , . "" IPv4- - , , .

, (, IPv4, ). RDBMS ( ), - .

, , , , .

, , ( ), , , / , MySQL ( ) t , , - , .

, , , , ? , WWPN , (hexstring ), ? , , , ( )? Etc...

, , , FieldFormatting: Table, Field, Format, CheckRules, LongFormat ( ) , -.

(, ) , , , / .

. , , , (, ), , . .

+1

All Articles