1. <tfoot id='nbd7m'></tfoot>
    <legend id='nbd7m'><style id='nbd7m'><dir id='nbd7m'><q id='nbd7m'></q></dir></style></legend>

    <small id='nbd7m'></small><noframes id='nbd7m'>

    1. <i id='nbd7m'><tr id='nbd7m'><dt id='nbd7m'><q id='nbd7m'><span id='nbd7m'><b id='nbd7m'><form id='nbd7m'><ins id='nbd7m'></ins><ul id='nbd7m'></ul><sub id='nbd7m'></sub></form><legend id='nbd7m'></legend><bdo id='nbd7m'><pre id='nbd7m'><center id='nbd7m'></center></pre></bdo></b><th id='nbd7m'></th></span></q></dt></tr></i><div id='nbd7m'><tfoot id='nbd7m'></tfoot><dl id='nbd7m'><fieldset id='nbd7m'></fieldset></dl></div>
        <bdo id='nbd7m'></bdo><ul id='nbd7m'></ul>

      MySQL、PostgreSQL、SQLite中数据库列类型的比较?(交叉映射)

      时间:2023-11-28
      <legend id='3G3FF'><style id='3G3FF'><dir id='3G3FF'><q id='3G3FF'></q></dir></style></legend>
      • <tfoot id='3G3FF'></tfoot>

            <tbody id='3G3FF'></tbody>

            <small id='3G3FF'></small><noframes id='3G3FF'>

            <i id='3G3FF'><tr id='3G3FF'><dt id='3G3FF'><q id='3G3FF'><span id='3G3FF'><b id='3G3FF'><form id='3G3FF'><ins id='3G3FF'></ins><ul id='3G3FF'></ul><sub id='3G3FF'></sub></form><legend id='3G3FF'></legend><bdo id='3G3FF'><pre id='3G3FF'><center id='3G3FF'></center></pre></bdo></b><th id='3G3FF'></th></span></q></dt></tr></i><div id='3G3FF'><tfoot id='3G3FF'></tfoot><dl id='3G3FF'><fieldset id='3G3FF'></fieldset></dl></div>
                <bdo id='3G3FF'></bdo><ul id='3G3FF'></ul>
                本文介绍了MySQL、PostgreSQL、SQLite中数据库列类型的比较?(交叉映射)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试找到某种方法来在最常用的数据库中关联列类型:MySQL, PostgreSQL 和 SQLite.

                I am trying to find some way to relate column types across the the most used Databases: MySQL, PostgreSQL, and SQLite.

                这是我目前所拥有的,但恐怕还没有完成,我需要一些有更多经验的人来帮助我完成任何缺失的类型.

                Here is what I have so far, but I'm afraid it's not done and I need some people with more experience to help me finish any missing types.

                MySQL                   PostgreSQL          SQLite
                
                TINYINT                 SMALLINT            INTEGER
                SMALLINT                SMALLINT
                MEDIUMINT               INTEGER
                BIGINT                  BIGINT
                BIT                     BIT                 INTEGER
                _______________________________________________________
                
                TINYINT UNSIGNED        SMALLINT            INTEGER
                SMALLINT UNSIGNED       INTEGER
                MEDIUMINT UNSIGNED      INTEGER
                INT UNSIGNED            BIGINT
                BIGINT UNSIGNED         NUMERIC(20)
                _______________________________________________________
                
                DOUBLE                  DOUBLE PRECISION    REAL
                FLOAT                   REAL                REAL
                DECIMAL                 DECIMAL             REAL
                NUMERIC                 NUMERIC             REAL
                _______________________________________________________
                
                BOOLEAN                 BOOLEAN             INTEGER
                _______________________________________________________
                
                DATE                    DATE                TEXT
                TIME                    TIME
                DATETIME                TIMESTAMP
                _______________________________________________________
                
                TIMESTAMP DEFAULT       TIMESTAMP DEFAULT   TEXT
                NOW()                   NOW()   
                _______________________________________________________
                
                LONGTEXT                TEXT                TEXT
                MEDIUMTEXT              TEXT                TEXT
                BLOB                    BYTEA               BLOB
                VARCHAR                 VARCHAR             TEXT
                CHAR                    CHAR                TEXT
                _______________________________________________________
                
                columnname INT          columnname SERIAL   INTEGER PRIMARY 
                AUTO_INCREMENT                              KEY AUTOINCREMENT
                

                推荐答案

                我会做不同的事情列表:

                MySQL 中的 MEDIUMINT 是一个奇怪的鸭子(3 个字节).我会避免它,但也将它映射到 INTEGER.

                MEDIUMINT in MySQL is an odd duck (3 bytes). I would avoid it, but otherwise map it to INTEGER too.

                MySQL BOOLEAN(别名 BOOL,别名 TINYINT(1))与 pg 布尔类型不兼容.您可能会或可能无法移植应用程序,具体取决于它们用作布尔文字的内容.在 MySQL 中,TRUE 和 FALSE 映射到 1 和 0 整数值.看起来 pg BOOLEAN 类型使用字符串文字表示法.因此,应用可能是也可能不是便携的——至少它不是替代品.

                The MySQL BOOLEAN (alias BOOL, alias TINYINT(1) ) is not compatible with the pg boolean type. You may or may not be able to port apps depending on what they use as boolean literals. In MySQL, TRUE and FALSE map to 1 and 0 integer values. It looks like the pg BOOLEAN type uses string literal notation. So apps may or may not be portable - at least it is no drop in replacement.

                最后,对于表格中的最后一行,我认为 SQLite 短语应为:

                Finally, for the last line in your tabl I think the SQLite phrase should read:

                INTEGER PRIMARY KEY AUTOINCREMENT
                

                这大致相当于

                BIGINT PRIMARY KEY AUTO_INCREMENT
                

                在 MySQL 中.在 postgres 中,SERIAL 数据类型产生一个 INTEGER 列,这与 MySQL 的

                in MySQL. In postgres, the SERIAL datatype results in an INTEGER column, and this will about the same as MySQL's

                INTEGER PRIMARY KEY AUTO_INCREMENT
                

                Postgres 也有一个 BIGSERIAL 类型,它与 SERIAL 相同,但使用 BIGINT 类型而不是 INT 类型.

                Postgres also has a BIGSERIAL type, which is the same as SERIAL but with a BIGINT type instead of an INT type.

                我错过了什么:

                我缺少 MySQL 的 INTEGER(别名 INT).它与 pg 中的 INTEGER 相当.非常重要的遗漏:VARCHAR 和 CHAR.在语义上,MySQL 和 PG 中的 VARCHAR 以及 MySQL 和 PG 中的 CHAR 是相同的,但在 MySQL 中,这些类型的最大长度要短得多.在 MySQL 中,这些类型的最大大小可以略小于 64kb,以 pg 1Gb(字节)为单位.实际长度说明符以字符数表示,因此如果您有一个多字节字符集,则必须将最大长度除以最大字符数才能获得为该字符集指定的理论最大长度.在 SQLite 中,VARCHAR 和 CHAR 都映射到 TEXT

                I am missing INTEGER (alias INT) for MySQL. It is comparable to INTEGER in pg. Very important omissions: VARCHAR and CHAR. Semantically, VARCHAR in MySQL and PG, and CHAR in MySQL and PG are the same, but in MySQL these types have a much shorter maximum length. In MySQL these types can have a maximum of a little less than 64kb, in pg 1Gb (bytes). The actual length specifier is expressed in the number of characters, so if you have a multi-byte character set, you have to divide the maximum lenght by the maximum number of characters to get the theoretical maximum length specified for that characterset. In SQLite, VARCHAR and CHAR map both to TEXT

                MySQL 和 PG 中 BIT 数据类型的语义大致相同,但 MySQL 中 BIT 数据类型的最大长度为 64(位)

                The BIT datatypes in MySQL and PG have roughly the same semantics, but in MySQL the maximum length of the BIT data type is 64 (bits)

                我认为 MySQL VARBINARY 数据类型最能与 PG 的 BYTEA 数据类型相媲美.(但确实 MySQL 的 BLOB 类型也映射到那个)

                I think the MySQL VARBINARY data type is best comparable to PG's BYTEA datatype. (but indeed MySQL's BLOB types also map to that)

                MySQL 中的 FLOAT 类型应该等同于 postgres 中的 REAL(以及 SQLite 中的 REAL)MySQL 中的 DECIMAL 类型等同于 postgres 中的 DECIMAL,除了在 postgres 中,该类型不对精度施加任意限制,而在 MySQL 中,最大精度是(我相信)70.(即 70 个数字位置)对于 MySQL 和 Postgres,NUMERIC 是 DECIMAL 类型的别名.

                The FLOAT type in MySQL should be equivalent to REAL in postgres (and REAL in SQLite too) The DECIMAL type in MySQL is equivalent to DECIMAL in postgres, except that in postgres, the type does not impose an arbtrary limit on the precision, whereas in MySQL the maximum precision is (i believe) 70. (that is, 70 number positions) For both MySQL and Postgres, NUMERIC is an alias for the DECIMAL type.

                这篇关于MySQL、PostgreSQL、SQLite中数据库列类型的比较?(交叉映射)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何在 SQL Server 中存储十进制值? 下一篇:MySQL 中的 VARCHAR(255) 和 TINYTEXT 字符串类型有什么区别?

                相关文章

                <small id='hjkdR'></small><noframes id='hjkdR'>

                    <bdo id='hjkdR'></bdo><ul id='hjkdR'></ul>
                  <legend id='hjkdR'><style id='hjkdR'><dir id='hjkdR'><q id='hjkdR'></q></dir></style></legend>

                  <i id='hjkdR'><tr id='hjkdR'><dt id='hjkdR'><q id='hjkdR'><span id='hjkdR'><b id='hjkdR'><form id='hjkdR'><ins id='hjkdR'></ins><ul id='hjkdR'></ul><sub id='hjkdR'></sub></form><legend id='hjkdR'></legend><bdo id='hjkdR'><pre id='hjkdR'><center id='hjkdR'></center></pre></bdo></b><th id='hjkdR'></th></span></q></dt></tr></i><div id='hjkdR'><tfoot id='hjkdR'></tfoot><dl id='hjkdR'><fieldset id='hjkdR'></fieldset></dl></div>
                1. <tfoot id='hjkdR'></tfoot>