Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Gpdb
提交
34411cfa
G
Gpdb
项目概览
Greenplum
/
Gpdb
通知
7
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Gpdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
34411cfa
编写于
10月 05, 2008
作者:
P
Peter Eisentraut
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Additional test coverage for int8 type (int8.c)
int8-exp-three-digits.out update untested, might need refinement.
上级
12884987
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
1134 addition
and
54 deletion
+1134
-54
src/test/regress/expected/int8-exp-three-digits.out
src/test/regress/expected/int8-exp-three-digits.out
+502
-25
src/test/regress/expected/int8.out
src/test/regress/expected/int8.out
+502
-25
src/test/regress/sql/int8.sql
src/test/regress/sql/int8.sql
+130
-4
未找到文件。
src/test/regress/expected/int8-exp-three-digits.out
浏览文件 @
34411cfa
...
@@ -6,8 +6,8 @@ CREATE TABLE INT8_TBL(q1 int8, q2 int8);
...
@@ -6,8 +6,8 @@ CREATE TABLE INT8_TBL(q1 int8, q2 int8);
INSERT INTO INT8_TBL VALUES(' 123 ',' 456');
INSERT INTO INT8_TBL VALUES(' 123 ',' 456');
INSERT INTO INT8_TBL VALUES('123 ','4567890123456789');
INSERT INTO INT8_TBL VALUES('123 ','4567890123456789');
INSERT INTO INT8_TBL VALUES('4567890123456789','123');
INSERT INTO INT8_TBL VALUES('4567890123456789','123');
INSERT INTO INT8_TBL VALUES(
'4567890123456789'
,'4567890123456789');
INSERT INTO INT8_TBL VALUES(
+4567890123456789
,'4567890123456789');
INSERT INTO INT8_TBL VALUES('4567890123456789','-4567890123456789');
INSERT INTO INT8_TBL VALUES('
+
4567890123456789','-4567890123456789');
-- bad inputs
-- bad inputs
INSERT INTO INT8_TBL(q1) VALUES (' ');
INSERT INTO INT8_TBL(q1) VALUES (' ');
ERROR: invalid input syntax for integer: " "
ERROR: invalid input syntax for integer: " "
...
@@ -47,6 +47,236 @@ SELECT * FROM INT8_TBL;
...
@@ -47,6 +47,236 @@ SELECT * FROM INT8_TBL;
4567890123456789 | -4567890123456789
4567890123456789 | -4567890123456789
(5 rows)
(5 rows)
-- int8/int8 cmp
SELECT * FROM INT8_TBL WHERE q2 = 4567890123456789;
q1 | q2
------------------+------------------
123 | 4567890123456789
4567890123456789 | 4567890123456789
(2 rows)
SELECT * FROM INT8_TBL WHERE q2 <> 4567890123456789;
q1 | q2
------------------+-------------------
123 | 456
4567890123456789 | 123
4567890123456789 | -4567890123456789
(3 rows)
SELECT * FROM INT8_TBL WHERE q2 < 4567890123456789;
q1 | q2
------------------+-------------------
123 | 456
4567890123456789 | 123
4567890123456789 | -4567890123456789
(3 rows)
SELECT * FROM INT8_TBL WHERE q2 > 4567890123456789;
q1 | q2
----+----
(0 rows)
SELECT * FROM INT8_TBL WHERE q2 <= 4567890123456789;
q1 | q2
------------------+-------------------
123 | 456
123 | 4567890123456789
4567890123456789 | 123
4567890123456789 | 4567890123456789
4567890123456789 | -4567890123456789
(5 rows)
SELECT * FROM INT8_TBL WHERE q2 >= 4567890123456789;
q1 | q2
------------------+------------------
123 | 4567890123456789
4567890123456789 | 4567890123456789
(2 rows)
-- int8/int4 cmp
SELECT * FROM INT8_TBL WHERE q2 = 456;
q1 | q2
-----+-----
123 | 456
(1 row)
SELECT * FROM INT8_TBL WHERE q2 <> 456;
q1 | q2
------------------+-------------------
123 | 4567890123456789
4567890123456789 | 123
4567890123456789 | 4567890123456789
4567890123456789 | -4567890123456789
(4 rows)
SELECT * FROM INT8_TBL WHERE q2 < 456;
q1 | q2
------------------+-------------------
4567890123456789 | 123
4567890123456789 | -4567890123456789
(2 rows)
SELECT * FROM INT8_TBL WHERE q2 > 456;
q1 | q2
------------------+------------------
123 | 4567890123456789
4567890123456789 | 4567890123456789
(2 rows)
SELECT * FROM INT8_TBL WHERE q2 <= 456;
q1 | q2
------------------+-------------------
123 | 456
4567890123456789 | 123
4567890123456789 | -4567890123456789
(3 rows)
SELECT * FROM INT8_TBL WHERE q2 >= 456;
q1 | q2
------------------+------------------
123 | 456
123 | 4567890123456789
4567890123456789 | 4567890123456789
(3 rows)
-- int4/int8 cmp
SELECT * FROM INT8_TBL WHERE 123 = q1;
q1 | q2
-----+------------------
123 | 456
123 | 4567890123456789
(2 rows)
SELECT * FROM INT8_TBL WHERE 123 <> q1;
q1 | q2
------------------+-------------------
4567890123456789 | 123
4567890123456789 | 4567890123456789
4567890123456789 | -4567890123456789
(3 rows)
SELECT * FROM INT8_TBL WHERE 123 < q1;
q1 | q2
------------------+-------------------
4567890123456789 | 123
4567890123456789 | 4567890123456789
4567890123456789 | -4567890123456789
(3 rows)
SELECT * FROM INT8_TBL WHERE 123 > q1;
q1 | q2
----+----
(0 rows)
SELECT * FROM INT8_TBL WHERE 123 <= q1;
q1 | q2
------------------+-------------------
123 | 456
123 | 4567890123456789
4567890123456789 | 123
4567890123456789 | 4567890123456789
4567890123456789 | -4567890123456789
(5 rows)
SELECT * FROM INT8_TBL WHERE 123 >= q1;
q1 | q2
-----+------------------
123 | 456
123 | 4567890123456789
(2 rows)
-- int8/int2 cmp
SELECT * FROM INT8_TBL WHERE q2 = '456'::int2;
q1 | q2
-----+-----
123 | 456
(1 row)
SELECT * FROM INT8_TBL WHERE q2 <> '456'::int2;
q1 | q2
------------------+-------------------
123 | 4567890123456789
4567890123456789 | 123
4567890123456789 | 4567890123456789
4567890123456789 | -4567890123456789
(4 rows)
SELECT * FROM INT8_TBL WHERE q2 < '456'::int2;
q1 | q2
------------------+-------------------
4567890123456789 | 123
4567890123456789 | -4567890123456789
(2 rows)
SELECT * FROM INT8_TBL WHERE q2 > '456'::int2;
q1 | q2
------------------+------------------
123 | 4567890123456789
4567890123456789 | 4567890123456789
(2 rows)
SELECT * FROM INT8_TBL WHERE q2 <= '456'::int2;
q1 | q2
------------------+-------------------
123 | 456
4567890123456789 | 123
4567890123456789 | -4567890123456789
(3 rows)
SELECT * FROM INT8_TBL WHERE q2 >= '456'::int2;
q1 | q2
------------------+------------------
123 | 456
123 | 4567890123456789
4567890123456789 | 4567890123456789
(3 rows)
-- int2/int8 cmp
SELECT * FROM INT8_TBL WHERE '123'::int2 = q1;
q1 | q2
-----+------------------
123 | 456
123 | 4567890123456789
(2 rows)
SELECT * FROM INT8_TBL WHERE '123'::int2 <> q1;
q1 | q2
------------------+-------------------
4567890123456789 | 123
4567890123456789 | 4567890123456789
4567890123456789 | -4567890123456789
(3 rows)
SELECT * FROM INT8_TBL WHERE '123'::int2 < q1;
q1 | q2
------------------+-------------------
4567890123456789 | 123
4567890123456789 | 4567890123456789
4567890123456789 | -4567890123456789
(3 rows)
SELECT * FROM INT8_TBL WHERE '123'::int2 > q1;
q1 | q2
----+----
(0 rows)
SELECT * FROM INT8_TBL WHERE '123'::int2 <= q1;
q1 | q2
------------------+-------------------
123 | 456
123 | 4567890123456789
4567890123456789 | 123
4567890123456789 | 4567890123456789
4567890123456789 | -4567890123456789
(5 rows)
SELECT * FROM INT8_TBL WHERE '123'::int2 >= q1;
q1 | q2
-----+------------------
123 | 456
123 | 4567890123456789
(2 rows)
SELECT '' AS five, q1 AS plus, -q1 AS minus FROM INT8_TBL;
SELECT '' AS five, q1 AS plus, -q1 AS minus FROM INT8_TBL;
five | plus | minus
five | plus | minus
------+------------------+-------------------
------+------------------+-------------------
...
@@ -88,34 +318,54 @@ SELECT '' AS three, q1, q2, q1 * q2 AS multiply FROM INT8_TBL
...
@@ -88,34 +318,54 @@ SELECT '' AS three, q1, q2, q1 * q2 AS multiply FROM INT8_TBL
| 4567890123456789 | 123 | 561850485185185047
| 4567890123456789 | 123 | 561850485185185047
(3 rows)
(3 rows)
SELECT '' AS five, q1, q2, q1 / q2 AS divide FROM INT8_TBL;
SELECT '' AS five, q1, q2, q1 / q2 AS divide
, q1 % q2 AS mod
FROM INT8_TBL;
five | q1 | q2 | divide
five | q1 | q2 | divide
| mod
------+------------------+-------------------+----------------
------+------------------+-------------------+----------------
+-----
| 123 | 456 | 0
| 123 | 456 | 0
| 123
| 123 | 4567890123456789 | 0
| 123 | 4567890123456789 | 0
| 123
| 4567890123456789 | 123 | 37137318076884
| 4567890123456789 | 123 | 37137318076884
| 57
| 4567890123456789 | 4567890123456789 | 1
| 4567890123456789 | 4567890123456789 | 1
| 0
| 4567890123456789 | -4567890123456789 | -1
| 4567890123456789 | -4567890123456789 | -1
| 0
(5 rows)
(5 rows)
SELECT '' AS five, q1, float8(q1) FROM INT8_TBL;
SELECT '' AS five, q1, float8(q1) FROM INT8_TBL;
five | q1 | float8
five | q1 | float8
------+------------------+----------------------
-
------+------------------+----------------------
| 123 |
123
| 123 | 123
| 123 |
123
| 123 | 123
| 4567890123456789 | 4.56789012345679e+
0
15
| 4567890123456789 | 4.56789012345679e+15
| 4567890123456789 | 4.56789012345679e+
0
15
| 4567890123456789 | 4.56789012345679e+15
| 4567890123456789 | 4.56789012345679e+
0
15
| 4567890123456789 | 4.56789012345679e+15
(5 rows)
(5 rows)
SELECT '' AS five, q2, float8(q2) FROM INT8_TBL;
SELECT '' AS five, q2, float8(q2) FROM INT8_TBL;
five | q2 | float8
five | q2 | float8
------+-------------------+------------------------
------+-------------------+-----------------------
| 456 | 456
| 456 | 456
| 4567890123456789 | 4.56789012345679e+015
| 4567890123456789 | 4.56789012345679e+15
| 123 | 123
| 123 | 123
| 4567890123456789 | 4.56789012345679e+015
| 4567890123456789 | 4.56789012345679e+15
| -4567890123456789 | -4.56789012345679e+015
| -4567890123456789 | -4.56789012345679e+15
(5 rows)
SELECT 37 + q1 AS plus4 FROM INT8_TBL;
plus4
------------------
160
160
4567890123456826
4567890123456826
4567890123456826
(5 rows)
SELECT 37 - q1 AS minus4 FROM INT8_TBL;
minus4
-------------------
-86
-86
-4567890123456752
-4567890123456752
-4567890123456752
(5 rows)
(5 rows)
SELECT '' AS five, 2 * q1 AS "twice int4" FROM INT8_TBL;
SELECT '' AS five, 2 * q1 AS "twice int4" FROM INT8_TBL;
...
@@ -138,6 +388,72 @@ SELECT '' AS five, q1 * 2 AS "twice int4" FROM INT8_TBL;
...
@@ -138,6 +388,72 @@ SELECT '' AS five, q1 * 2 AS "twice int4" FROM INT8_TBL;
| 9135780246913578
| 9135780246913578
(5 rows)
(5 rows)
-- int8 op int4
SELECT q1 + 42::int4 AS "8plus4", q1 - 42::int4 AS "8minus4", q1 * 42::int4 AS "8mul4", q1 / 42::int4 AS "8div4" FROM INT8_TBL;
8plus4 | 8minus4 | 8mul4 | 8div4
------------------+------------------+--------------------+-----------------
165 | 81 | 5166 | 2
165 | 81 | 5166 | 2
4567890123456831 | 4567890123456747 | 191851385185185138 | 108759288653733
4567890123456831 | 4567890123456747 | 191851385185185138 | 108759288653733
4567890123456831 | 4567890123456747 | 191851385185185138 | 108759288653733
(5 rows)
-- int4 op int8
SELECT 246::int4 + q1 AS "4plus8", 246::int4 - q1 AS "4minus8", 246::int4 * q1 AS "4mul8", 246::int4 / q1 AS "4div8" FROM INT8_TBL;
4plus8 | 4minus8 | 4mul8 | 4div8
------------------+-------------------+---------------------+-------
369 | 123 | 30258 | 2
369 | 123 | 30258 | 2
4567890123457035 | -4567890123456543 | 1123700970370370094 | 0
4567890123457035 | -4567890123456543 | 1123700970370370094 | 0
4567890123457035 | -4567890123456543 | 1123700970370370094 | 0
(5 rows)
-- int8 op int2
SELECT q1 + 42::int2 AS "8plus2", q1 - 42::int2 AS "8minus2", q1 * 42::int2 AS "8mul2", q1 / 42::int2 AS "8div2" FROM INT8_TBL;
8plus2 | 8minus2 | 8mul2 | 8div2
------------------+------------------+--------------------+-----------------
165 | 81 | 5166 | 2
165 | 81 | 5166 | 2
4567890123456831 | 4567890123456747 | 191851385185185138 | 108759288653733
4567890123456831 | 4567890123456747 | 191851385185185138 | 108759288653733
4567890123456831 | 4567890123456747 | 191851385185185138 | 108759288653733
(5 rows)
-- int2 op int8
SELECT 246::int2 + q1 AS "2plus8", 246::int2 - q1 AS "2minus8", 246::int2 * q1 AS "2mul8", 246::int2 / q1 AS "2div8" FROM INT8_TBL;
2plus8 | 2minus8 | 2mul8 | 2div8
------------------+-------------------+---------------------+-------
369 | 123 | 30258 | 2
369 | 123 | 30258 | 2
4567890123457035 | -4567890123456543 | 1123700970370370094 | 0
4567890123457035 | -4567890123456543 | 1123700970370370094 | 0
4567890123457035 | -4567890123456543 | 1123700970370370094 | 0
(5 rows)
SELECT q2, abs(q2) FROM INT8_TBL;
q2 | abs
-------------------+------------------
456 | 456
4567890123456789 | 4567890123456789
123 | 123
4567890123456789 | 4567890123456789
-4567890123456789 | 4567890123456789
(5 rows)
SELECT min(q1), min(q2) FROM INT8_TBL;
min | min
-----+-------------------
123 | -4567890123456789
(1 row)
SELECT max(q1), max(q2) FROM INT8_TBL;
max | max
------------------+------------------
4567890123456789 | 4567890123456789
(1 row)
-- TO_CHAR()
-- TO_CHAR()
--
--
SELECT '' AS to_char_1, to_char(q1, '9G999G999G999G999G999'), to_char(q2, '9,999,999,999,999,999')
SELECT '' AS to_char_1, to_char(q1, '9G999G999G999G999G999'), to_char(q2, '9,999,999,999,999,999')
...
@@ -314,7 +630,7 @@ SELECT '' AS to_char_17, to_char(q2, '999999SG9999999999') FROM INT8_TBL;
...
@@ -314,7 +630,7 @@ SELECT '' AS to_char_17, to_char(q2, '999999SG9999999999') FROM INT8_TBL;
| 456789-0123456789
| 456789-0123456789
(5 rows)
(5 rows)
-- check min/max values
-- check min/max values
and overflow behavior
select '-9223372036854775808'::int8;
select '-9223372036854775808'::int8;
int8
int8
----------------------
----------------------
...
@@ -335,3 +651,164 @@ select '9223372036854775808'::int8;
...
@@ -335,3 +651,164 @@ select '9223372036854775808'::int8;
ERROR: value "9223372036854775808" is out of range for type bigint
ERROR: value "9223372036854775808" is out of range for type bigint
LINE 1: select '9223372036854775808'::int8;
LINE 1: select '9223372036854775808'::int8;
^
^
select -('-9223372036854775807'::int8);
?column?
---------------------
9223372036854775807
(1 row)
select -('-9223372036854775808'::int8);
ERROR: bigint out of range
select '9223372036854775800'::int8 + '9223372036854775800'::int8;
ERROR: bigint out of range
select '-9223372036854775800'::int8 + '-9223372036854775800'::int8;
ERROR: bigint out of range
select '9223372036854775800'::int8 - '-9223372036854775800'::int8;
ERROR: bigint out of range
select '-9223372036854775800'::int8 - '9223372036854775800'::int8;
ERROR: bigint out of range
select '9223372036854775800'::int8 * '9223372036854775800'::int8;
ERROR: bigint out of range
select '-9223372036854775808'::int8 / '-1'::int8;
ERROR: bigint out of range
select '9223372036854775800'::int8 / '0'::int8;
ERROR: division by zero
select '9223372036854775800'::int8 % '0'::int8;
ERROR: division by zero
select abs('-9223372036854775808'::int8);
ERROR: bigint out of range
select '9223372036854775800'::int8 + '100'::int4;
ERROR: bigint out of range
select '-9223372036854775800'::int8 - '100'::int4;
ERROR: bigint out of range
select '9223372036854775800'::int8 * '100'::int4;
ERROR: bigint out of range
select '-9223372036854775808'::int8 / '-1'::int4;
ERROR: bigint out of range
select '100'::int4 + '9223372036854775800'::int8;
ERROR: bigint out of range
select '-100'::int4 - '9223372036854775800'::int8;
ERROR: bigint out of range
select '100'::int4 * '9223372036854775800'::int8;
ERROR: bigint out of range
select '9223372036854775800'::int8 + '100'::int2;
ERROR: bigint out of range
select '-9223372036854775800'::int8 - '100'::int2;
ERROR: bigint out of range
select '9223372036854775800'::int8 * '100'::int2;
ERROR: bigint out of range
select '-9223372036854775808'::int8 / '-1'::int2;
ERROR: bigint out of range
select '-9223372036854775808'::int8 / '0'::int2;
ERROR: division by zero
select '100'::int2 + '9223372036854775800'::int8;
ERROR: bigint out of range
select '-100'::int2 - '9223372036854775800'::int8;
ERROR: bigint out of range
select '100'::int2 * '9223372036854775800'::int8;
ERROR: bigint out of range
select '100'::int2 / '0'::int8;
ERROR: division by zero
SELECT CAST(q1 AS int4) FROM int8_tbl WHERE q2 = 456;
q1
-----
123
(1 row)
SELECT CAST(q1 AS int4) FROM int8_tbl WHERE q2 <> 456;
ERROR: integer out of range
SELECT CAST(q1 AS int2) FROM int8_tbl WHERE q2 = 456;
q1
-----
123
(1 row)
SELECT CAST(q1 AS int2) FROM int8_tbl WHERE q2 <> 456;
ERROR: smallint out of range
SELECT CAST('42'::int2 AS int8), CAST('-37'::int2 AS int8);
int8 | int8
------+------
42 | -37
(1 row)
SELECT CAST(q1 AS float4), CAST(q2 AS float8) FROM INT8_TBL;
q1 | q2
-------------+-----------------------
123 | 456
123 | 4.56789012345679e+15
4.56789e+15 | 123
4.56789e+15 | 4.56789012345679e+15
4.56789e+15 | -4.56789012345679e+15
(5 rows)
SELECT CAST('36854775807.0'::float4 AS int8);
int8
-------------
36854775808
(1 row)
SELECT CAST('9223372036854775807.0'::float4 AS int8);
ERROR: bigint out of range
SELECT CAST('9223372036854775807.0'::float8 AS int8);
ERROR: bigint out of range
SELECT CAST('922337203685477580700.0'::float8 AS int8);
ERROR: bigint out of range
SELECT CAST(q1 AS oid) FROM INT8_TBL;
ERROR: OID out of range
SELECT oid::int8 FROM pg_class WHERE relname = 'pg_class';
oid
------
1259
(1 row)
-- bit operations
SELECT q1, q2, q1 & q2 AS "and", q1 | q2 AS "or", q1 # q2 AS "xor", ~q1 AS "not" FROM INT8_TBL;
q1 | q2 | and | or | xor | not
------------------+-------------------+------------------+------------------+------------------+-------------------
123 | 456 | 72 | 507 | 435 | -124
123 | 4567890123456789 | 17 | 4567890123456895 | 4567890123456878 | -124
4567890123456789 | 123 | 17 | 4567890123456895 | 4567890123456878 | -4567890123456790
4567890123456789 | 4567890123456789 | 4567890123456789 | 4567890123456789 | 0 | -4567890123456790
4567890123456789 | -4567890123456789 | 1 | -1 | -2 | -4567890123456790
(5 rows)
SELECT q1, q1 << 2 AS "shl", q1 >> 3 AS "shr" FROM INT8_TBL;
q1 | shl | shr
------------------+-------------------+-----------------
123 | 492 | 15
123 | 492 | 15
4567890123456789 | 18271560493827156 | 570986265432098
4567890123456789 | 18271560493827156 | 570986265432098
4567890123456789 | 18271560493827156 | 570986265432098
(5 rows)
-- generate_series
SELECT * FROM generate_series('+4567890123456789'::int8, '+4567890123456799'::int8);
generate_series
------------------
4567890123456789
4567890123456790
4567890123456791
4567890123456792
4567890123456793
4567890123456794
4567890123456795
4567890123456796
4567890123456797
4567890123456798
4567890123456799
(11 rows)
SELECT * FROM generate_series('+4567890123456789'::int8, '+4567890123456799'::int8, 0);
ERROR: step size cannot equal zero
SELECT * FROM generate_series('+4567890123456789'::int8, '+4567890123456799'::int8, 2);
generate_series
------------------
4567890123456789
4567890123456791
4567890123456793
4567890123456795
4567890123456797
4567890123456799
(6 rows)
src/test/regress/expected/int8.out
浏览文件 @
34411cfa
...
@@ -6,8 +6,8 @@ CREATE TABLE INT8_TBL(q1 int8, q2 int8);
...
@@ -6,8 +6,8 @@ CREATE TABLE INT8_TBL(q1 int8, q2 int8);
INSERT INTO INT8_TBL VALUES(' 123 ',' 456');
INSERT INTO INT8_TBL VALUES(' 123 ',' 456');
INSERT INTO INT8_TBL VALUES('123 ','4567890123456789');
INSERT INTO INT8_TBL VALUES('123 ','4567890123456789');
INSERT INTO INT8_TBL VALUES('4567890123456789','123');
INSERT INTO INT8_TBL VALUES('4567890123456789','123');
INSERT INTO INT8_TBL VALUES(
'4567890123456789'
,'4567890123456789');
INSERT INTO INT8_TBL VALUES(
+4567890123456789
,'4567890123456789');
INSERT INTO INT8_TBL VALUES('4567890123456789','-4567890123456789');
INSERT INTO INT8_TBL VALUES('
+
4567890123456789','-4567890123456789');
-- bad inputs
-- bad inputs
INSERT INTO INT8_TBL(q1) VALUES (' ');
INSERT INTO INT8_TBL(q1) VALUES (' ');
ERROR: invalid input syntax for integer: " "
ERROR: invalid input syntax for integer: " "
...
@@ -47,6 +47,236 @@ SELECT * FROM INT8_TBL;
...
@@ -47,6 +47,236 @@ SELECT * FROM INT8_TBL;
4567890123456789 | -4567890123456789
4567890123456789 | -4567890123456789
(5 rows)
(5 rows)
-- int8/int8 cmp
SELECT * FROM INT8_TBL WHERE q2 = 4567890123456789;
q1 | q2
------------------+------------------
123 | 4567890123456789
4567890123456789 | 4567890123456789
(2 rows)
SELECT * FROM INT8_TBL WHERE q2 <> 4567890123456789;
q1 | q2
------------------+-------------------
123 | 456
4567890123456789 | 123
4567890123456789 | -4567890123456789
(3 rows)
SELECT * FROM INT8_TBL WHERE q2 < 4567890123456789;
q1 | q2
------------------+-------------------
123 | 456
4567890123456789 | 123
4567890123456789 | -4567890123456789
(3 rows)
SELECT * FROM INT8_TBL WHERE q2 > 4567890123456789;
q1 | q2
----+----
(0 rows)
SELECT * FROM INT8_TBL WHERE q2 <= 4567890123456789;
q1 | q2
------------------+-------------------
123 | 456
123 | 4567890123456789
4567890123456789 | 123
4567890123456789 | 4567890123456789
4567890123456789 | -4567890123456789
(5 rows)
SELECT * FROM INT8_TBL WHERE q2 >= 4567890123456789;
q1 | q2
------------------+------------------
123 | 4567890123456789
4567890123456789 | 4567890123456789
(2 rows)
-- int8/int4 cmp
SELECT * FROM INT8_TBL WHERE q2 = 456;
q1 | q2
-----+-----
123 | 456
(1 row)
SELECT * FROM INT8_TBL WHERE q2 <> 456;
q1 | q2
------------------+-------------------
123 | 4567890123456789
4567890123456789 | 123
4567890123456789 | 4567890123456789
4567890123456789 | -4567890123456789
(4 rows)
SELECT * FROM INT8_TBL WHERE q2 < 456;
q1 | q2
------------------+-------------------
4567890123456789 | 123
4567890123456789 | -4567890123456789
(2 rows)
SELECT * FROM INT8_TBL WHERE q2 > 456;
q1 | q2
------------------+------------------
123 | 4567890123456789
4567890123456789 | 4567890123456789
(2 rows)
SELECT * FROM INT8_TBL WHERE q2 <= 456;
q1 | q2
------------------+-------------------
123 | 456
4567890123456789 | 123
4567890123456789 | -4567890123456789
(3 rows)
SELECT * FROM INT8_TBL WHERE q2 >= 456;
q1 | q2
------------------+------------------
123 | 456
123 | 4567890123456789
4567890123456789 | 4567890123456789
(3 rows)
-- int4/int8 cmp
SELECT * FROM INT8_TBL WHERE 123 = q1;
q1 | q2
-----+------------------
123 | 456
123 | 4567890123456789
(2 rows)
SELECT * FROM INT8_TBL WHERE 123 <> q1;
q1 | q2
------------------+-------------------
4567890123456789 | 123
4567890123456789 | 4567890123456789
4567890123456789 | -4567890123456789
(3 rows)
SELECT * FROM INT8_TBL WHERE 123 < q1;
q1 | q2
------------------+-------------------
4567890123456789 | 123
4567890123456789 | 4567890123456789
4567890123456789 | -4567890123456789
(3 rows)
SELECT * FROM INT8_TBL WHERE 123 > q1;
q1 | q2
----+----
(0 rows)
SELECT * FROM INT8_TBL WHERE 123 <= q1;
q1 | q2
------------------+-------------------
123 | 456
123 | 4567890123456789
4567890123456789 | 123
4567890123456789 | 4567890123456789
4567890123456789 | -4567890123456789
(5 rows)
SELECT * FROM INT8_TBL WHERE 123 >= q1;
q1 | q2
-----+------------------
123 | 456
123 | 4567890123456789
(2 rows)
-- int8/int2 cmp
SELECT * FROM INT8_TBL WHERE q2 = '456'::int2;
q1 | q2
-----+-----
123 | 456
(1 row)
SELECT * FROM INT8_TBL WHERE q2 <> '456'::int2;
q1 | q2
------------------+-------------------
123 | 4567890123456789
4567890123456789 | 123
4567890123456789 | 4567890123456789
4567890123456789 | -4567890123456789
(4 rows)
SELECT * FROM INT8_TBL WHERE q2 < '456'::int2;
q1 | q2
------------------+-------------------
4567890123456789 | 123
4567890123456789 | -4567890123456789
(2 rows)
SELECT * FROM INT8_TBL WHERE q2 > '456'::int2;
q1 | q2
------------------+------------------
123 | 4567890123456789
4567890123456789 | 4567890123456789
(2 rows)
SELECT * FROM INT8_TBL WHERE q2 <= '456'::int2;
q1 | q2
------------------+-------------------
123 | 456
4567890123456789 | 123
4567890123456789 | -4567890123456789
(3 rows)
SELECT * FROM INT8_TBL WHERE q2 >= '456'::int2;
q1 | q2
------------------+------------------
123 | 456
123 | 4567890123456789
4567890123456789 | 4567890123456789
(3 rows)
-- int2/int8 cmp
SELECT * FROM INT8_TBL WHERE '123'::int2 = q1;
q1 | q2
-----+------------------
123 | 456
123 | 4567890123456789
(2 rows)
SELECT * FROM INT8_TBL WHERE '123'::int2 <> q1;
q1 | q2
------------------+-------------------
4567890123456789 | 123
4567890123456789 | 4567890123456789
4567890123456789 | -4567890123456789
(3 rows)
SELECT * FROM INT8_TBL WHERE '123'::int2 < q1;
q1 | q2
------------------+-------------------
4567890123456789 | 123
4567890123456789 | 4567890123456789
4567890123456789 | -4567890123456789
(3 rows)
SELECT * FROM INT8_TBL WHERE '123'::int2 > q1;
q1 | q2
----+----
(0 rows)
SELECT * FROM INT8_TBL WHERE '123'::int2 <= q1;
q1 | q2
------------------+-------------------
123 | 456
123 | 4567890123456789
4567890123456789 | 123
4567890123456789 | 4567890123456789
4567890123456789 | -4567890123456789
(5 rows)
SELECT * FROM INT8_TBL WHERE '123'::int2 >= q1;
q1 | q2
-----+------------------
123 | 456
123 | 4567890123456789
(2 rows)
SELECT '' AS five, q1 AS plus, -q1 AS minus FROM INT8_TBL;
SELECT '' AS five, q1 AS plus, -q1 AS minus FROM INT8_TBL;
five | plus | minus
five | plus | minus
------+------------------+-------------------
------+------------------+-------------------
...
@@ -88,34 +318,54 @@ SELECT '' AS three, q1, q2, q1 * q2 AS multiply FROM INT8_TBL
...
@@ -88,34 +318,54 @@ SELECT '' AS three, q1, q2, q1 * q2 AS multiply FROM INT8_TBL
| 4567890123456789 | 123 | 561850485185185047
| 4567890123456789 | 123 | 561850485185185047
(3 rows)
(3 rows)
SELECT '' AS five, q1, q2, q1 / q2 AS divide FROM INT8_TBL;
SELECT '' AS five, q1, q2, q1 / q2 AS divide
, q1 % q2 AS mod
FROM INT8_TBL;
five | q1 | q2 | divide
five | q1 | q2 | divide
| mod
------+------------------+-------------------+----------------
------+------------------+-------------------+----------------
+-----
| 123 | 456 | 0
| 123 | 456 | 0
| 123
| 123 | 4567890123456789 | 0
| 123 | 4567890123456789 | 0
| 123
| 4567890123456789 | 123 | 37137318076884
| 4567890123456789 | 123 | 37137318076884
| 57
| 4567890123456789 | 4567890123456789 | 1
| 4567890123456789 | 4567890123456789 | 1
| 0
| 4567890123456789 | -4567890123456789 | -1
| 4567890123456789 | -4567890123456789 | -1
| 0
(5 rows)
(5 rows)
SELECT '' AS five, q1, float8(q1) FROM INT8_TBL;
SELECT '' AS five, q1, float8(q1) FROM INT8_TBL;
five | q1 | float8
five | q1 | float8
------+------------------+----------------------
------+------------------+----------------------
-
| 123 | 123
| 123 |
123
| 123 | 123
| 123 |
123
| 4567890123456789 | 4.56789012345679e+15
| 4567890123456789 | 4.56789012345679e+
0
15
| 4567890123456789 | 4.56789012345679e+15
| 4567890123456789 | 4.56789012345679e+
0
15
| 4567890123456789 | 4.56789012345679e+15
| 4567890123456789 | 4.56789012345679e+
0
15
(5 rows)
(5 rows)
SELECT '' AS five, q2, float8(q2) FROM INT8_TBL;
SELECT '' AS five, q2, float8(q2) FROM INT8_TBL;
five | q2 | float8
five | q2 | float8
------+-------------------+-----------------------
------+-------------------+------------------------
| 456 | 456
| 456 | 456
| 4567890123456789 | 4.56789012345679e+15
| 4567890123456789 | 4.56789012345679e+015
| 123 | 123
| 123 | 123
| 4567890123456789 | 4.56789012345679e+15
| 4567890123456789 | 4.56789012345679e+015
| -4567890123456789 | -4.56789012345679e+15
| -4567890123456789 | -4.56789012345679e+015
(5 rows)
SELECT 37 + q1 AS plus4 FROM INT8_TBL;
plus4
------------------
160
160
4567890123456826
4567890123456826
4567890123456826
(5 rows)
SELECT 37 - q1 AS minus4 FROM INT8_TBL;
minus4
-------------------
-86
-86
-4567890123456752
-4567890123456752
-4567890123456752
(5 rows)
(5 rows)
SELECT '' AS five, 2 * q1 AS "twice int4" FROM INT8_TBL;
SELECT '' AS five, 2 * q1 AS "twice int4" FROM INT8_TBL;
...
@@ -138,6 +388,72 @@ SELECT '' AS five, q1 * 2 AS "twice int4" FROM INT8_TBL;
...
@@ -138,6 +388,72 @@ SELECT '' AS five, q1 * 2 AS "twice int4" FROM INT8_TBL;
| 9135780246913578
| 9135780246913578
(5 rows)
(5 rows)
-- int8 op int4
SELECT q1 + 42::int4 AS "8plus4", q1 - 42::int4 AS "8minus4", q1 * 42::int4 AS "8mul4", q1 / 42::int4 AS "8div4" FROM INT8_TBL;
8plus4 | 8minus4 | 8mul4 | 8div4
------------------+------------------+--------------------+-----------------
165 | 81 | 5166 | 2
165 | 81 | 5166 | 2
4567890123456831 | 4567890123456747 | 191851385185185138 | 108759288653733
4567890123456831 | 4567890123456747 | 191851385185185138 | 108759288653733
4567890123456831 | 4567890123456747 | 191851385185185138 | 108759288653733
(5 rows)
-- int4 op int8
SELECT 246::int4 + q1 AS "4plus8", 246::int4 - q1 AS "4minus8", 246::int4 * q1 AS "4mul8", 246::int4 / q1 AS "4div8" FROM INT8_TBL;
4plus8 | 4minus8 | 4mul8 | 4div8
------------------+-------------------+---------------------+-------
369 | 123 | 30258 | 2
369 | 123 | 30258 | 2
4567890123457035 | -4567890123456543 | 1123700970370370094 | 0
4567890123457035 | -4567890123456543 | 1123700970370370094 | 0
4567890123457035 | -4567890123456543 | 1123700970370370094 | 0
(5 rows)
-- int8 op int2
SELECT q1 + 42::int2 AS "8plus2", q1 - 42::int2 AS "8minus2", q1 * 42::int2 AS "8mul2", q1 / 42::int2 AS "8div2" FROM INT8_TBL;
8plus2 | 8minus2 | 8mul2 | 8div2
------------------+------------------+--------------------+-----------------
165 | 81 | 5166 | 2
165 | 81 | 5166 | 2
4567890123456831 | 4567890123456747 | 191851385185185138 | 108759288653733
4567890123456831 | 4567890123456747 | 191851385185185138 | 108759288653733
4567890123456831 | 4567890123456747 | 191851385185185138 | 108759288653733
(5 rows)
-- int2 op int8
SELECT 246::int2 + q1 AS "2plus8", 246::int2 - q1 AS "2minus8", 246::int2 * q1 AS "2mul8", 246::int2 / q1 AS "2div8" FROM INT8_TBL;
2plus8 | 2minus8 | 2mul8 | 2div8
------------------+-------------------+---------------------+-------
369 | 123 | 30258 | 2
369 | 123 | 30258 | 2
4567890123457035 | -4567890123456543 | 1123700970370370094 | 0
4567890123457035 | -4567890123456543 | 1123700970370370094 | 0
4567890123457035 | -4567890123456543 | 1123700970370370094 | 0
(5 rows)
SELECT q2, abs(q2) FROM INT8_TBL;
q2 | abs
-------------------+------------------
456 | 456
4567890123456789 | 4567890123456789
123 | 123
4567890123456789 | 4567890123456789
-4567890123456789 | 4567890123456789
(5 rows)
SELECT min(q1), min(q2) FROM INT8_TBL;
min | min
-----+-------------------
123 | -4567890123456789
(1 row)
SELECT max(q1), max(q2) FROM INT8_TBL;
max | max
------------------+------------------
4567890123456789 | 4567890123456789
(1 row)
-- TO_CHAR()
-- TO_CHAR()
--
--
SELECT '' AS to_char_1, to_char(q1, '9G999G999G999G999G999'), to_char(q2, '9,999,999,999,999,999')
SELECT '' AS to_char_1, to_char(q1, '9G999G999G999G999G999'), to_char(q2, '9,999,999,999,999,999')
...
@@ -314,7 +630,7 @@ SELECT '' AS to_char_17, to_char(q2, '999999SG9999999999') FROM INT8_TBL;
...
@@ -314,7 +630,7 @@ SELECT '' AS to_char_17, to_char(q2, '999999SG9999999999') FROM INT8_TBL;
| 456789-0123456789
| 456789-0123456789
(5 rows)
(5 rows)
-- check min/max values
-- check min/max values
and overflow behavior
select '-9223372036854775808'::int8;
select '-9223372036854775808'::int8;
int8
int8
----------------------
----------------------
...
@@ -335,3 +651,164 @@ select '9223372036854775808'::int8;
...
@@ -335,3 +651,164 @@ select '9223372036854775808'::int8;
ERROR: value "9223372036854775808" is out of range for type bigint
ERROR: value "9223372036854775808" is out of range for type bigint
LINE 1: select '9223372036854775808'::int8;
LINE 1: select '9223372036854775808'::int8;
^
^
select -('-9223372036854775807'::int8);
?column?
---------------------
9223372036854775807
(1 row)
select -('-9223372036854775808'::int8);
ERROR: bigint out of range
select '9223372036854775800'::int8 + '9223372036854775800'::int8;
ERROR: bigint out of range
select '-9223372036854775800'::int8 + '-9223372036854775800'::int8;
ERROR: bigint out of range
select '9223372036854775800'::int8 - '-9223372036854775800'::int8;
ERROR: bigint out of range
select '-9223372036854775800'::int8 - '9223372036854775800'::int8;
ERROR: bigint out of range
select '9223372036854775800'::int8 * '9223372036854775800'::int8;
ERROR: bigint out of range
select '-9223372036854775808'::int8 / '-1'::int8;
ERROR: bigint out of range
select '9223372036854775800'::int8 / '0'::int8;
ERROR: division by zero
select '9223372036854775800'::int8 % '0'::int8;
ERROR: division by zero
select abs('-9223372036854775808'::int8);
ERROR: bigint out of range
select '9223372036854775800'::int8 + '100'::int4;
ERROR: bigint out of range
select '-9223372036854775800'::int8 - '100'::int4;
ERROR: bigint out of range
select '9223372036854775800'::int8 * '100'::int4;
ERROR: bigint out of range
select '-9223372036854775808'::int8 / '-1'::int4;
ERROR: bigint out of range
select '100'::int4 + '9223372036854775800'::int8;
ERROR: bigint out of range
select '-100'::int4 - '9223372036854775800'::int8;
ERROR: bigint out of range
select '100'::int4 * '9223372036854775800'::int8;
ERROR: bigint out of range
select '9223372036854775800'::int8 + '100'::int2;
ERROR: bigint out of range
select '-9223372036854775800'::int8 - '100'::int2;
ERROR: bigint out of range
select '9223372036854775800'::int8 * '100'::int2;
ERROR: bigint out of range
select '-9223372036854775808'::int8 / '-1'::int2;
ERROR: bigint out of range
select '-9223372036854775808'::int8 / '0'::int2;
ERROR: division by zero
select '100'::int2 + '9223372036854775800'::int8;
ERROR: bigint out of range
select '-100'::int2 - '9223372036854775800'::int8;
ERROR: bigint out of range
select '100'::int2 * '9223372036854775800'::int8;
ERROR: bigint out of range
select '100'::int2 / '0'::int8;
ERROR: division by zero
SELECT CAST(q1 AS int4) FROM int8_tbl WHERE q2 = 456;
q1
-----
123
(1 row)
SELECT CAST(q1 AS int4) FROM int8_tbl WHERE q2 <> 456;
ERROR: integer out of range
SELECT CAST(q1 AS int2) FROM int8_tbl WHERE q2 = 456;
q1
-----
123
(1 row)
SELECT CAST(q1 AS int2) FROM int8_tbl WHERE q2 <> 456;
ERROR: smallint out of range
SELECT CAST('42'::int2 AS int8), CAST('-37'::int2 AS int8);
int8 | int8
------+------
42 | -37
(1 row)
SELECT CAST(q1 AS float4), CAST(q2 AS float8) FROM INT8_TBL;
q1 | q2
-------------+-----------------------
123 | 456
123 | 4.56789012345679e+15
4.56789e+15 | 123
4.56789e+15 | 4.56789012345679e+15
4.56789e+15 | -4.56789012345679e+15
(5 rows)
SELECT CAST('36854775807.0'::float4 AS int8);
int8
-------------
36854775808
(1 row)
SELECT CAST('9223372036854775807.0'::float4 AS int8);
ERROR: bigint out of range
SELECT CAST('9223372036854775807.0'::float8 AS int8);
ERROR: bigint out of range
SELECT CAST('922337203685477580700.0'::float8 AS int8);
ERROR: bigint out of range
SELECT CAST(q1 AS oid) FROM INT8_TBL;
ERROR: OID out of range
SELECT oid::int8 FROM pg_class WHERE relname = 'pg_class';
oid
------
1259
(1 row)
-- bit operations
SELECT q1, q2, q1 & q2 AS "and", q1 | q2 AS "or", q1 # q2 AS "xor", ~q1 AS "not" FROM INT8_TBL;
q1 | q2 | and | or | xor | not
------------------+-------------------+------------------+------------------+------------------+-------------------
123 | 456 | 72 | 507 | 435 | -124
123 | 4567890123456789 | 17 | 4567890123456895 | 4567890123456878 | -124
4567890123456789 | 123 | 17 | 4567890123456895 | 4567890123456878 | -4567890123456790
4567890123456789 | 4567890123456789 | 4567890123456789 | 4567890123456789 | 0 | -4567890123456790
4567890123456789 | -4567890123456789 | 1 | -1 | -2 | -4567890123456790
(5 rows)
SELECT q1, q1 << 2 AS "shl", q1 >> 3 AS "shr" FROM INT8_TBL;
q1 | shl | shr
------------------+-------------------+-----------------
123 | 492 | 15
123 | 492 | 15
4567890123456789 | 18271560493827156 | 570986265432098
4567890123456789 | 18271560493827156 | 570986265432098
4567890123456789 | 18271560493827156 | 570986265432098
(5 rows)
-- generate_series
SELECT * FROM generate_series('+4567890123456789'::int8, '+4567890123456799'::int8);
generate_series
------------------
4567890123456789
4567890123456790
4567890123456791
4567890123456792
4567890123456793
4567890123456794
4567890123456795
4567890123456796
4567890123456797
4567890123456798
4567890123456799
(11 rows)
SELECT * FROM generate_series('+4567890123456789'::int8, '+4567890123456799'::int8, 0);
ERROR: step size cannot equal zero
SELECT * FROM generate_series('+4567890123456789'::int8, '+4567890123456799'::int8, 2);
generate_series
------------------
4567890123456789
4567890123456791
4567890123456793
4567890123456795
4567890123456797
4567890123456799
(6 rows)
src/test/regress/sql/int8.sql
浏览文件 @
34411cfa
...
@@ -7,8 +7,8 @@ CREATE TABLE INT8_TBL(q1 int8, q2 int8);
...
@@ -7,8 +7,8 @@ CREATE TABLE INT8_TBL(q1 int8, q2 int8);
INSERT
INTO
INT8_TBL
VALUES
(
' 123 '
,
' 456'
);
INSERT
INTO
INT8_TBL
VALUES
(
' 123 '
,
' 456'
);
INSERT
INTO
INT8_TBL
VALUES
(
'123 '
,
'4567890123456789'
);
INSERT
INTO
INT8_TBL
VALUES
(
'123 '
,
'4567890123456789'
);
INSERT
INTO
INT8_TBL
VALUES
(
'4567890123456789'
,
'123'
);
INSERT
INTO
INT8_TBL
VALUES
(
'4567890123456789'
,
'123'
);
INSERT
INTO
INT8_TBL
VALUES
(
'4567890123456789'
,
'4567890123456789'
);
INSERT
INTO
INT8_TBL
VALUES
(
+
4567890123456789
,
'4567890123456789'
);
INSERT
INTO
INT8_TBL
VALUES
(
'4567890123456789'
,
'-4567890123456789'
);
INSERT
INTO
INT8_TBL
VALUES
(
'
+
4567890123456789'
,
'-4567890123456789'
);
-- bad inputs
-- bad inputs
INSERT
INTO
INT8_TBL
(
q1
)
VALUES
(
' '
);
INSERT
INTO
INT8_TBL
(
q1
)
VALUES
(
' '
);
...
@@ -21,6 +21,47 @@ INSERT INTO INT8_TBL(q1) VALUES ('');
...
@@ -21,6 +21,47 @@ INSERT INTO INT8_TBL(q1) VALUES ('');
SELECT
*
FROM
INT8_TBL
;
SELECT
*
FROM
INT8_TBL
;
-- int8/int8 cmp
SELECT
*
FROM
INT8_TBL
WHERE
q2
=
4567890123456789
;
SELECT
*
FROM
INT8_TBL
WHERE
q2
<>
4567890123456789
;
SELECT
*
FROM
INT8_TBL
WHERE
q2
<
4567890123456789
;
SELECT
*
FROM
INT8_TBL
WHERE
q2
>
4567890123456789
;
SELECT
*
FROM
INT8_TBL
WHERE
q2
<=
4567890123456789
;
SELECT
*
FROM
INT8_TBL
WHERE
q2
>=
4567890123456789
;
-- int8/int4 cmp
SELECT
*
FROM
INT8_TBL
WHERE
q2
=
456
;
SELECT
*
FROM
INT8_TBL
WHERE
q2
<>
456
;
SELECT
*
FROM
INT8_TBL
WHERE
q2
<
456
;
SELECT
*
FROM
INT8_TBL
WHERE
q2
>
456
;
SELECT
*
FROM
INT8_TBL
WHERE
q2
<=
456
;
SELECT
*
FROM
INT8_TBL
WHERE
q2
>=
456
;
-- int4/int8 cmp
SELECT
*
FROM
INT8_TBL
WHERE
123
=
q1
;
SELECT
*
FROM
INT8_TBL
WHERE
123
<>
q1
;
SELECT
*
FROM
INT8_TBL
WHERE
123
<
q1
;
SELECT
*
FROM
INT8_TBL
WHERE
123
>
q1
;
SELECT
*
FROM
INT8_TBL
WHERE
123
<=
q1
;
SELECT
*
FROM
INT8_TBL
WHERE
123
>=
q1
;
-- int8/int2 cmp
SELECT
*
FROM
INT8_TBL
WHERE
q2
=
'456'
::
int2
;
SELECT
*
FROM
INT8_TBL
WHERE
q2
<>
'456'
::
int2
;
SELECT
*
FROM
INT8_TBL
WHERE
q2
<
'456'
::
int2
;
SELECT
*
FROM
INT8_TBL
WHERE
q2
>
'456'
::
int2
;
SELECT
*
FROM
INT8_TBL
WHERE
q2
<=
'456'
::
int2
;
SELECT
*
FROM
INT8_TBL
WHERE
q2
>=
'456'
::
int2
;
-- int2/int8 cmp
SELECT
*
FROM
INT8_TBL
WHERE
'123'
::
int2
=
q1
;
SELECT
*
FROM
INT8_TBL
WHERE
'123'
::
int2
<>
q1
;
SELECT
*
FROM
INT8_TBL
WHERE
'123'
::
int2
<
q1
;
SELECT
*
FROM
INT8_TBL
WHERE
'123'
::
int2
>
q1
;
SELECT
*
FROM
INT8_TBL
WHERE
'123'
::
int2
<=
q1
;
SELECT
*
FROM
INT8_TBL
WHERE
'123'
::
int2
>=
q1
;
SELECT
''
AS
five
,
q1
AS
plus
,
-
q1
AS
minus
FROM
INT8_TBL
;
SELECT
''
AS
five
,
q1
AS
plus
,
-
q1
AS
minus
FROM
INT8_TBL
;
SELECT
''
AS
five
,
q1
,
q2
,
q1
+
q2
AS
plus
FROM
INT8_TBL
;
SELECT
''
AS
five
,
q1
,
q2
,
q1
+
q2
AS
plus
FROM
INT8_TBL
;
...
@@ -28,14 +69,31 @@ SELECT '' AS five, q1, q2, q1 - q2 AS minus FROM INT8_TBL;
...
@@ -28,14 +69,31 @@ SELECT '' AS five, q1, q2, q1 - q2 AS minus FROM INT8_TBL;
SELECT
''
AS
three
,
q1
,
q2
,
q1
*
q2
AS
multiply
FROM
INT8_TBL
;
SELECT
''
AS
three
,
q1
,
q2
,
q1
*
q2
AS
multiply
FROM
INT8_TBL
;
SELECT
''
AS
three
,
q1
,
q2
,
q1
*
q2
AS
multiply
FROM
INT8_TBL
SELECT
''
AS
three
,
q1
,
q2
,
q1
*
q2
AS
multiply
FROM
INT8_TBL
WHERE
q1
<
1000
or
(
q2
>
0
and
q2
<
1000
);
WHERE
q1
<
1000
or
(
q2
>
0
and
q2
<
1000
);
SELECT
''
AS
five
,
q1
,
q2
,
q1
/
q2
AS
divide
FROM
INT8_TBL
;
SELECT
''
AS
five
,
q1
,
q2
,
q1
/
q2
AS
divide
,
q1
%
q2
AS
mod
FROM
INT8_TBL
;
SELECT
''
AS
five
,
q1
,
float8
(
q1
)
FROM
INT8_TBL
;
SELECT
''
AS
five
,
q1
,
float8
(
q1
)
FROM
INT8_TBL
;
SELECT
''
AS
five
,
q2
,
float8
(
q2
)
FROM
INT8_TBL
;
SELECT
''
AS
five
,
q2
,
float8
(
q2
)
FROM
INT8_TBL
;
SELECT
37
+
q1
AS
plus4
FROM
INT8_TBL
;
SELECT
37
-
q1
AS
minus4
FROM
INT8_TBL
;
SELECT
''
AS
five
,
2
*
q1
AS
"twice int4"
FROM
INT8_TBL
;
SELECT
''
AS
five
,
2
*
q1
AS
"twice int4"
FROM
INT8_TBL
;
SELECT
''
AS
five
,
q1
*
2
AS
"twice int4"
FROM
INT8_TBL
;
SELECT
''
AS
five
,
q1
*
2
AS
"twice int4"
FROM
INT8_TBL
;
-- int8 op int4
SELECT
q1
+
42
::
int4
AS
"8plus4"
,
q1
-
42
::
int4
AS
"8minus4"
,
q1
*
42
::
int4
AS
"8mul4"
,
q1
/
42
::
int4
AS
"8div4"
FROM
INT8_TBL
;
-- int4 op int8
SELECT
246
::
int4
+
q1
AS
"4plus8"
,
246
::
int4
-
q1
AS
"4minus8"
,
246
::
int4
*
q1
AS
"4mul8"
,
246
::
int4
/
q1
AS
"4div8"
FROM
INT8_TBL
;
-- int8 op int2
SELECT
q1
+
42
::
int2
AS
"8plus2"
,
q1
-
42
::
int2
AS
"8minus2"
,
q1
*
42
::
int2
AS
"8mul2"
,
q1
/
42
::
int2
AS
"8div2"
FROM
INT8_TBL
;
-- int2 op int8
SELECT
246
::
int2
+
q1
AS
"2plus8"
,
246
::
int2
-
q1
AS
"2minus8"
,
246
::
int2
*
q1
AS
"2mul8"
,
246
::
int2
/
q1
AS
"2div8"
FROM
INT8_TBL
;
SELECT
q2
,
abs
(
q2
)
FROM
INT8_TBL
;
SELECT
min
(
q1
),
min
(
q2
)
FROM
INT8_TBL
;
SELECT
max
(
q1
),
max
(
q2
)
FROM
INT8_TBL
;
-- TO_CHAR()
-- TO_CHAR()
--
--
SELECT
''
AS
to_char_1
,
to_char
(
q1
,
'9G999G999G999G999G999'
),
to_char
(
q2
,
'9,999,999,999,999,999'
)
SELECT
''
AS
to_char_1
,
to_char
(
q1
,
'9G999G999G999G999G999'
),
to_char
(
q2
,
'9,999,999,999,999,999'
)
...
@@ -64,8 +122,76 @@ SELECT '' AS to_char_15, to_char(q2, 'S 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 . 9 9 9'
...
@@ -64,8 +122,76 @@ SELECT '' AS to_char_15, to_char(q2, 'S 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 . 9 9 9'
SELECT
''
AS
to_char_16
,
to_char
(
q2
,
E
'99999 "text" 9999 "9999" 999 "
\\
"text between quote marks
\\
"" 9999'
)
FROM
INT8_TBL
;
SELECT
''
AS
to_char_16
,
to_char
(
q2
,
E
'99999 "text" 9999 "9999" 999 "
\\
"text between quote marks
\\
"" 9999'
)
FROM
INT8_TBL
;
SELECT
''
AS
to_char_17
,
to_char
(
q2
,
'999999SG9999999999'
)
FROM
INT8_TBL
;
SELECT
''
AS
to_char_17
,
to_char
(
q2
,
'999999SG9999999999'
)
FROM
INT8_TBL
;
-- check min/max values
-- check min/max values and overflow behavior
select
'-9223372036854775808'
::
int8
;
select
'-9223372036854775808'
::
int8
;
select
'-9223372036854775809'
::
int8
;
select
'-9223372036854775809'
::
int8
;
select
'9223372036854775807'
::
int8
;
select
'9223372036854775807'
::
int8
;
select
'9223372036854775808'
::
int8
;
select
'9223372036854775808'
::
int8
;
select
-
(
'-9223372036854775807'
::
int8
);
select
-
(
'-9223372036854775808'
::
int8
);
select
'9223372036854775800'
::
int8
+
'9223372036854775800'
::
int8
;
select
'-9223372036854775800'
::
int8
+
'-9223372036854775800'
::
int8
;
select
'9223372036854775800'
::
int8
-
'-9223372036854775800'
::
int8
;
select
'-9223372036854775800'
::
int8
-
'9223372036854775800'
::
int8
;
select
'9223372036854775800'
::
int8
*
'9223372036854775800'
::
int8
;
select
'-9223372036854775808'
::
int8
/
'-1'
::
int8
;
select
'9223372036854775800'
::
int8
/
'0'
::
int8
;
select
'9223372036854775800'
::
int8
%
'0'
::
int8
;
select
abs
(
'-9223372036854775808'
::
int8
);
select
'9223372036854775800'
::
int8
+
'100'
::
int4
;
select
'-9223372036854775800'
::
int8
-
'100'
::
int4
;
select
'9223372036854775800'
::
int8
*
'100'
::
int4
;
select
'-9223372036854775808'
::
int8
/
'-1'
::
int4
;
select
'100'
::
int4
+
'9223372036854775800'
::
int8
;
select
'-100'
::
int4
-
'9223372036854775800'
::
int8
;
select
'100'
::
int4
*
'9223372036854775800'
::
int8
;
select
'9223372036854775800'
::
int8
+
'100'
::
int2
;
select
'-9223372036854775800'
::
int8
-
'100'
::
int2
;
select
'9223372036854775800'
::
int8
*
'100'
::
int2
;
select
'-9223372036854775808'
::
int8
/
'-1'
::
int2
;
select
'-9223372036854775808'
::
int8
/
'0'
::
int2
;
select
'100'
::
int2
+
'9223372036854775800'
::
int8
;
select
'-100'
::
int2
-
'9223372036854775800'
::
int8
;
select
'100'
::
int2
*
'9223372036854775800'
::
int8
;
select
'100'
::
int2
/
'0'
::
int8
;
SELECT
CAST
(
q1
AS
int4
)
FROM
int8_tbl
WHERE
q2
=
456
;
SELECT
CAST
(
q1
AS
int4
)
FROM
int8_tbl
WHERE
q2
<>
456
;
SELECT
CAST
(
q1
AS
int2
)
FROM
int8_tbl
WHERE
q2
=
456
;
SELECT
CAST
(
q1
AS
int2
)
FROM
int8_tbl
WHERE
q2
<>
456
;
SELECT
CAST
(
'42'
::
int2
AS
int8
),
CAST
(
'-37'
::
int2
AS
int8
);
SELECT
CAST
(
q1
AS
float4
),
CAST
(
q2
AS
float8
)
FROM
INT8_TBL
;
SELECT
CAST
(
'36854775807.0'
::
float4
AS
int8
);
SELECT
CAST
(
'9223372036854775807.0'
::
float4
AS
int8
);
SELECT
CAST
(
'9223372036854775807.0'
::
float8
AS
int8
);
SELECT
CAST
(
'922337203685477580700.0'
::
float8
AS
int8
);
SELECT
CAST
(
q1
AS
oid
)
FROM
INT8_TBL
;
SELECT
oid
::
int8
FROM
pg_class
WHERE
relname
=
'pg_class'
;
-- bit operations
SELECT
q1
,
q2
,
q1
&
q2
AS
"and"
,
q1
|
q2
AS
"or"
,
q1
#
q2
AS
"xor"
,
~
q1
AS
"not"
FROM
INT8_TBL
;
SELECT
q1
,
q1
<<
2
AS
"shl"
,
q1
>>
3
AS
"shr"
FROM
INT8_TBL
;
-- generate_series
SELECT
*
FROM
generate_series
(
'+4567890123456789'
::
int8
,
'+4567890123456799'
::
int8
);
SELECT
*
FROM
generate_series
(
'+4567890123456789'
::
int8
,
'+4567890123456799'
::
int8
,
0
);
SELECT
*
FROM
generate_series
(
'+4567890123456789'
::
int8
,
'+4567890123456799'
::
int8
,
2
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录