开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 20

shenguo/IvorySQL

forked from IvorySQL/IvorySQL
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (47)
标签 (571)
master
IVORY_REL_5_STABLE
IVORY_REL_2_STABLE
coderabbitai/docstrings/e7d0b3a
IVORY_REL_4_STABLE
IVORYSQL_REL_1_STABLE
IVORYSQL_REL_1_PERF
revert-749-ora_rowid
IVORY_REL_3_STABLE
revert-668-merge_pg_master
revert-281-Unified6
revert-256-master
IVORY_REL_1_STABLE
REL_15_STABLE
REL_13_STABLE
REL_14_STABLE
REL9_6_STABLE
REL_10_STABLE
REL_11_STABLE
REL_12_STABLE
IvorySQL_5.0
IvorySQL_4.6
IvorySQL_4.5.3
IvorySQL_4.5.2
IvorySQL_4.5.1
IvorySQL_4.5
IvorySQL_1.17
IvorySQL_4.4
IvorySQL_4.2
IvorySQL_4.0
Ivory_REL_1_8
IvorySQL_3.4
IvorySQL_3.3
IvorySQL_3.2
IvorySQL_3.1
IvorySQL_3.0
Ivorysql_3.0_Beta
Ivory_REL_2_3
Ivory_REL_2_2
Ivory_REL_2_1
master
分支 (47)
标签 (571)
master
IVORY_REL_5_STABLE
IVORY_REL_2_STABLE
coderabbitai/docstrings/e7d0b3a
IVORY_REL_4_STABLE
IVORYSQL_REL_1_STABLE
IVORYSQL_REL_1_PERF
revert-749-ora_rowid
IVORY_REL_3_STABLE
revert-668-merge_pg_master
revert-281-Unified6
revert-256-master
IVORY_REL_1_STABLE
REL_15_STABLE
REL_13_STABLE
REL_14_STABLE
REL9_6_STABLE
REL_10_STABLE
REL_11_STABLE
REL_12_STABLE
IvorySQL_5.0
IvorySQL_4.6
IvorySQL_4.5.3
IvorySQL_4.5.2
IvorySQL_4.5.1
IvorySQL_4.5
IvorySQL_1.17
IvorySQL_4.4
IvorySQL_4.2
IvorySQL_4.0
Ivory_REL_1_8
IvorySQL_3.4
IvorySQL_3.3
IvorySQL_3.2
IvorySQL_3.1
IvorySQL_3.0
Ivorysql_3.0_Beta
Ivory_REL_2_3
Ivory_REL_2_2
Ivory_REL_2_1
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (47)
标签 (571)
master
IVORY_REL_5_STABLE
IVORY_REL_2_STABLE
coderabbitai/docstrings/e7d0b3a
IVORY_REL_4_STABLE
IVORYSQL_REL_1_STABLE
IVORYSQL_REL_1_PERF
revert-749-ora_rowid
IVORY_REL_3_STABLE
revert-668-merge_pg_master
revert-281-Unified6
revert-256-master
IVORY_REL_1_STABLE
REL_15_STABLE
REL_13_STABLE
REL_14_STABLE
REL9_6_STABLE
REL_10_STABLE
REL_11_STABLE
REL_12_STABLE
IvorySQL_5.0
IvorySQL_4.6
IvorySQL_4.5.3
IvorySQL_4.5.2
IvorySQL_4.5.1
IvorySQL_4.5
IvorySQL_1.17
IvorySQL_4.4
IvorySQL_4.2
IvorySQL_4.0
Ivory_REL_1_8
IvorySQL_3.4
IvorySQL_3.3
IvorySQL_3.2
IvorySQL_3.1
IvorySQL_3.0
Ivorysql_3.0_Beta
Ivory_REL_2_3
Ivory_REL_2_2
Ivory_REL_2_1
IvorySQL
/
src
/
tutorial
/
complex.source
IvorySQL
/
src
/
tutorial
/
complex.source
complex.source 7.40 KB
一键复制 编辑 原始数据 按行查看 历史
Bruce Momjian 提交于 2025年01月02日 00:21 +08:00 . Update copyright for 2025
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
---------------------------------------------------------------------------
--
-- complex.sql-
-- This file shows how to create a new user-defined type and how to
-- use this new type.
--
--
-- Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
-- Portions Copyright (c) 1994, Regents of the University of California
--
-- src/tutorial/complex.source
--
---------------------------------------------------------------------------
-----------------------------
-- Creating a new type:
-- We are going to create a new type called 'complex' which represents
-- complex numbers.
-- A user-defined type must have an input and an output function, and
-- optionally can have binary input and output functions. All of these
-- are usually user-defined C functions.
-----------------------------
-- Assume the user defined functions are in _OBJWD_/complex$DLSUFFIX
-- (we do not want to assume this is in the dynamic loader search path).
-- Look at $PWD/complex.c for the source. Note that we declare all of
-- them as STRICT, so we do not need to cope with NULL inputs in the
-- C code. We also mark them IMMUTABLE, since they always return the
-- same outputs given the same inputs.
-- the input function 'complex_in' takes a null-terminated string (the
-- textual representation of the type) and turns it into the internal
-- (in memory) representation. You will get a message telling you 'complex'
-- does not exist yet but that's okay.
CREATE FUNCTION complex_in(cstring)
RETURNS complex
AS '_OBJWD_/complex'
LANGUAGE C IMMUTABLE STRICT;
-- the output function 'complex_out' takes the internal representation and
-- converts it into the textual representation.
CREATE FUNCTION complex_out(complex)
RETURNS cstring
AS '_OBJWD_/complex'
LANGUAGE C IMMUTABLE STRICT;
-- the binary input function 'complex_recv' takes a StringInfo buffer
-- and turns its contents into the internal representation.
CREATE FUNCTION complex_recv(internal)
RETURNS complex
AS '_OBJWD_/complex'
LANGUAGE C IMMUTABLE STRICT;
-- the binary output function 'complex_send' takes the internal representation
-- and converts it into a (hopefully) platform-independent bytea string.
CREATE FUNCTION complex_send(complex)
RETURNS bytea
AS '_OBJWD_/complex'
LANGUAGE C IMMUTABLE STRICT;
-- now, we can create the type. The internallength specifies the size of the
-- memory block required to hold the type (we need two 8-byte doubles).
CREATE TYPE complex (
internallength = 16,
input = complex_in,
output = complex_out,
receive = complex_recv,
send = complex_send,
alignment = double
);
-----------------------------
-- Using the new type:
-- user-defined types can be used like ordinary built-in types.
-----------------------------
-- eg. we can use it in a table
CREATE TABLE test_complex (
a complex,
b complex
);
-- data for user-defined types are just strings in the proper textual
-- representation.
INSERT INTO test_complex VALUES ('(1.0, 2.5)', '(4.2, 3.55 )');
INSERT INTO test_complex VALUES ('(33.0, 51.4)', '(100.42, 93.55)');
SELECT * FROM test_complex;
-----------------------------
-- Creating an operator for the new type:
-- Let's define an add operator for complex types. Since POSTGRES
-- supports function overloading, we'll use + as the add operator.
-- (Operator names can be reused with different numbers and types of
-- arguments.)
-----------------------------
-- first, define a function complex_add (also in complex.c)
CREATE FUNCTION complex_add(complex, complex)
RETURNS complex
AS '_OBJWD_/complex'
LANGUAGE C IMMUTABLE STRICT;
-- we can now define the operator. We show a binary operator here but you
-- can also define a prefix operator by omitting the leftarg.
CREATE OPERATOR + (
leftarg = complex,
rightarg = complex,
procedure = complex_add,
commutator = +
);
SELECT (a + b) AS c FROM test_complex;
-- Occasionally, you may find it useful to cast the string to the desired
-- type explicitly. :: denotes a type cast.
SELECT a + '(1.0,1.0)'::complex AS aa,
b + '(1.0,1.0)'::complex AS bb
FROM test_complex;
-----------------------------
-- Creating aggregate functions
-- you can also define aggregate functions. The syntax is somewhat
-- cryptic but the idea is to express the aggregate in terms of state
-- transition functions.
-----------------------------
CREATE AGGREGATE complex_sum (
sfunc = complex_add,
basetype = complex,
stype = complex,
initcond = '(0,0)'
);
SELECT complex_sum(a) FROM test_complex;
-----------------------------
-- Interfacing New Types with Indexes:
-- We cannot define a secondary index (eg. a B-tree) over the new type
-- yet. We need to create all the required operators and support
-- functions, then we can make the operator class.
-----------------------------
-- first, define the required operators
CREATE FUNCTION complex_abs_lt(complex, complex) RETURNS bool
AS '_OBJWD_/complex' LANGUAGE C IMMUTABLE STRICT;
CREATE FUNCTION complex_abs_le(complex, complex) RETURNS bool
AS '_OBJWD_/complex' LANGUAGE C IMMUTABLE STRICT;
CREATE FUNCTION complex_abs_eq(complex, complex) RETURNS bool
AS '_OBJWD_/complex' LANGUAGE C IMMUTABLE STRICT;
CREATE FUNCTION complex_abs_ge(complex, complex) RETURNS bool
AS '_OBJWD_/complex' LANGUAGE C IMMUTABLE STRICT;
CREATE FUNCTION complex_abs_gt(complex, complex) RETURNS bool
AS '_OBJWD_/complex' LANGUAGE C IMMUTABLE STRICT;
CREATE OPERATOR < (
leftarg = complex, rightarg = complex, procedure = complex_abs_lt,
commutator = > , negator = >= ,
restrict = scalarltsel, join = scalarltjoinsel
);
CREATE OPERATOR <= (
leftarg = complex, rightarg = complex, procedure = complex_abs_le,
commutator = >= , negator = > ,
restrict = scalarlesel, join = scalarlejoinsel
);
CREATE OPERATOR = (
leftarg = complex, rightarg = complex, procedure = complex_abs_eq,
commutator = = ,
-- leave out negator since we didn't create <> operator
-- negator = <> ,
restrict = eqsel, join = eqjoinsel
);
CREATE OPERATOR >= (
leftarg = complex, rightarg = complex, procedure = complex_abs_ge,
commutator = <= , negator = < ,
restrict = scalargesel, join = scalargejoinsel
);
CREATE OPERATOR > (
leftarg = complex, rightarg = complex, procedure = complex_abs_gt,
commutator = < , negator = <= ,
restrict = scalargtsel, join = scalargtjoinsel
);
-- create the support function too
CREATE FUNCTION complex_abs_cmp(complex, complex) RETURNS int4
AS '_OBJWD_/complex' LANGUAGE C IMMUTABLE STRICT;
-- now we can make the operator class
CREATE OPERATOR CLASS complex_abs_ops
DEFAULT FOR TYPE complex USING btree AS
OPERATOR 1 < ,
OPERATOR 2 <= ,
OPERATOR 3 = ,
OPERATOR 4 >= ,
OPERATOR 5 > ,
FUNCTION 1 complex_abs_cmp(complex, complex);
-- now, we can define a btree index on complex types. First, let's populate
-- the table. Note that postgres needs many more tuples to start using the
-- btree index during selects.
INSERT INTO test_complex VALUES ('(56.0,-22.5)', '(-43.2,-0.07)');
INSERT INTO test_complex VALUES ('(-91.9,33.6)', '(8.6,3.0)');
CREATE INDEX test_cplx_ind ON test_complex
USING btree(a complex_abs_ops);
SELECT * from test_complex where a = '(56.0,-22.5)';
SELECT * from test_complex where a < '(56.0,-22.5)';
SELECT * from test_complex where a > '(56.0,-22.5)';
-- clean up the example
DROP TABLE test_complex;
DROP TYPE complex CASCADE;
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

暂无描述
暂无标签
Apache-2.0
使用 Apache-2.0 开源许可协议
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/gersa/IvorySQL.git
git@gitee.com:gersa/IvorySQL.git
gersa
IvorySQL
IvorySQL
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /