bigint

mysql中int、bigint、smallint、tinyint 长度

坚强是说给别人听的谎言 提交于 2019-11-30 18:35:40
mysql中int、bigint、smallint、tinyint 长度 bigint -2^63 (-9223372036854775808) 到 2^63-1 (9223372036854775807) 的整型数据,存储大小为 8 个字节。 int -2^31 (-2,147,483,648) 到 2^31-1 (2,147,483,647) 的整型数据,存储大小为 4 个字节。 smallint -2^15 (-32,768) 到 2^15-1 (32,767) 的整型数据,存储大小为 2 个字节。 tinyint 0 到 255 的整型数据。存储大小为 1 字节。 参考链接 来源: https://www.cnblogs.com/GetcharZp/p/11635004.html

What is the limit of the field type BIGINT in SQL?

好久不见. 提交于 2019-11-30 18:25:38
What is the limit of the field type BIGINT in SQL? is 100000235882380 or 100000466411115 acceptable? (That is ID from facebook) Dan Grossman Check the manual of the RDBMS you're using. It may not be the same in all systems. MySQL: https://dev.mysql.com/doc/refman/5.7/en/integer-types.html PostgreSQL: https://www.postgresql.org/docs/10/static/datatype-numeric.html SQL Server (Transact-SQL): https://docs.microsoft.com/en-us/sql/t-sql/data-types/int-bigint-smallint-and-tinyint-transact-sql DB2: http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=/com.ibm.db29.doc.sqlref/db2z

杂谈自增主键用完了怎么办

南笙酒味 提交于 2019-11-30 13:04:47
引言 在面试中,大家应该经历过如下场景 面试官:"用过mysql吧,你们是用自增主键还是UUID?" 你:"用的是自增主键" 面试官:"为什么是自增主键?" 你:"因为采用自增主键,数据在物理结构上是顺序存储,性能最好,blabla..." 面试官:"那自增主键达到最大值了,用完了怎么办?" 你:"what,没复习啊!!" (然后,你就可以回去等通知了!) 这个问题是一个粉丝给我提的,我觉得挺有 意(KENG)思(B)! 于是,今天我们就来谈一谈,这个自增主键用完了该怎么办! 正文 简单版 我们先明白一点,在mysql中,Int整型的范围如下 类型 最小值 最大值 存储大小 Int(有符号) -2147483648 2147483648 4 bytes Int(无符号) 0 4294967295 4 bytes 我们以无符号整型为例,存储范围为0~4294967295,约43亿!我们先说一下,一旦自增id达到最大值,此时数据继续插入是会报一个主键冲突异常如下所示 //Duplicate entry '4294967295' for key 'PRIMARY' 那解决方法也是很简单的,将Int类型改为BigInt类型,BigInt的范围如下 类型 最小值 最大值 存储大小 BigInt(有符号) -9223372036854775808 9223372036854775808 8

BES-项目中使用的MyBatis Collection嵌套查询

随声附和 提交于 2019-11-30 04:37:55
User表嵌套查Role表(一对多) User表和Role表的结构 CREATE TABLE t_user ( id BIGINT NOT NULL COMMENT '用户ID', position_id BIGINT COMMENT '职位ID', department_id BIGINT COMMENT '部门ID', code VARCHAR(32) UNIQUE NOT NULL COMMENT '用户编码', password VARCHAR(32) COMMENT '密码', name VARCHAR(32) UNIQUE NOT NULL COMMENT '用户名称', ... (其他字段) PRIMARY KEY (id) ); CREATE TABLE t_role ( id BIGINT NOT NULL COMMENT '角色ID', company_id BIGINT COMMENT '公司ID', org_id BIGINT COMMENT '机构ID', code VARCHAR(32) UNIQUE COMMENT '角色代码', name VARCHAR(32) NOT NULL COMMENT '角色名称', ...(其他字段) PRIMARY KEY (id) ); User和Role的entity:为节省篇幅,删除了代码中的注释、构造函数

FreeSql (三十三)CodeFirst 类型映射

安稳与你 提交于 2019-11-29 20:48:49
前面有介绍过几篇 CodeFirst 内容文章,有 《FreeSql (二) 自动迁移实体》( https://www.cnblogs.com/FreeSql/p/11531301.html ) 《FreeSql (三)实体特性》( https://www.cnblogs.com/FreeSql/p/11531302.html ) 《FreeSql (四)实体特性 Fluent Api》( https://www.cnblogs.com/FreeSql/p/11531304.html ) 入门 FreeSql 前这些算是基础教程,需要提前了解,接下来进入 CodeFirst 功能的深入了解。 类型映射是 ORM 最重要的功能之一,FreeSql 支持五大数据库大多数数据库类型,包括 mysql 的 enum/set,pgsql 的 hstore/jsonb 等等。。除此默认之外,还提供了自定义类型映射。 类型映射,需要考虑写入(我们的写入需要考虑 NoneParameter 和 Parameter)、读取时的转换工作,这部分扩展对个人使用者而言比较复杂,如有需要请提出您的 issues。 FreeSql 拥有较高容错处理,如:当数据库类型为 bigint 可空,实体类为 int 时,读取数据不会出错。 自定义类型映射(MapType) class EnumTestMap {

021 商品规格管理

独自空忆成欢 提交于 2019-11-29 18:25:10
1.商品规格数据结构 乐优商城是一个全品类的电商网站,因此商品的种类繁多,每一件商品,其属性又有差别。为了更准确描述商品及细分差别,抽象出两个概念:SPU和SKU,了解一下: (1)SPU和SKU SPU:Standard Product Unit (标准产品单位) ,一组具有共同属性的商品集 SKU:Stock Keeping Unit(库存量单位),SPU商品集因具体特性不同而细分的每个商品 以图为例来看: 本页的 华为Mate10 就是一个商品集(SPU) 因为颜色、内存等不同,而细分出不同的Mate10,如亮黑色128G版。(SKU) 可以看出: SPU是一个抽象的商品集概念,为了方便后台的管理。 SKU才是具体要销售的商品,每一个SKU的价格、库存可能会不一样,用户购买的是SKU而不是SPU (2)规格参数表 <1>表结构 我们看下规格参数的格式: 可以看到规格参数是分组的,每一组都有多个参数键值对。不过对于规格参数的模板而言,其值现在是不确定的,不同的商品值肯定不同,模板中只要保存组信息、组内参数信息即可。 因此我们设计了两张表: tb_spec_group:组,与商品分类关联 tb_spec_param:参数名,与组关联,一对多 <2>规格组 规格参数分组表:tb_spec_group CREATE TABLE `tb_spec_group` ( `id`

Converting a big integer to decimal string

放肆的年华 提交于 2019-11-29 12:01:43
At the risk of having this question voted as a duplicate, or even to have it closed, I had this question has come up. Background In "normal" data types such as int, long long, etc..., to convert from the binary numeric value to a decimal string, you would do the following (in pseudo code): Set length = 0 Set divisor to largest base10 value the data type will hold (Divisor). Loop Divide number in question by divisor. Place result in a string at position length. Increment the length by 1. Divide the divisor by 10. Reverse the string. Print the string. The actual implementation in (most) any

Base 36 to BigInt?

廉价感情. 提交于 2019-11-29 10:54:46
Suppose I want to convert a base-36 encoded string to a BigInt , I can do this: BigInt(parseInt(x,36)) But what if my string exceeds what can safely fit in a Number ? e.g. parseInt('zzzzzzzzzzzzz',36) Then I start losing precision. Are there any methods for parsing directly into a BigInt ? You could convert the number to a bigint type. function convert(value, radix) { return [...value.toString()] .reduce((r, v) => r * BigInt(radix) + BigInt(parseInt(v, radix)), 0n); } console.log(convert('zzzzzzzzzzzzz', 36).toString()); With greater chunks, like just for example with ten (eleven return a

AcWing 114. 国王游戏(贪心)

六眼飞鱼酱① 提交于 2019-11-29 08:10:30
传送门 #include <bits/stdc++.h> using namespace std; constexpr int base = 1000000000; constexpr int base_digits = 9; struct bigint { // value == 0 is represented by empty z vector<int> z; // digits // sign == 1 <==> value >= 0 // sign == -1 <==> value < 0 int sign; bigint() : sign(1) {} bigint(long long v) { *this = v; } bigint &operator=(long long v) { sign = v < 0 ? -1 : 1; v *= sign; z.clear(); for (; v > 0; v = v / base) z.push_back((int) (v % base)); return *this; } bigint(const string &s) { read(s); } bigint &operator+=(const bigint &other) { if (sign == other.sign) { for (int i = 0, carry

How to format bigint field into a date in Postgresql?

空扰寡人 提交于 2019-11-29 02:48:17
I have a table with a field of type bigint. This field store a timestamp. I want to date format the field like this : to_char( bigint_field,'DD/MM/YYYY HH24:MI:SS') I get the following error : ERROR: multiple decimal points État SQL :42601 TO_CHAR(TO_TIMESTAMP(bigint_field / 1000), 'DD/MM/YYYY HH24:MI:SS') Jordan K This depends on what the bigint value represents - offset of epoch time, or not. select to_timestamp(20120822193532::text, 'YYYYMMDDHH24MISS') returns "2012-08-22 19:35:32+00" I did it like this: to_timestamp(to_char(20120822193532, '9999-99-99 99:99:99'),'YYYY-MM-DD HH24:MI:SS')