c - PostgreSQL - 创建索引

标签 c postgresql indexing

我正在使用 PostgreSQL 创建一些用 C 编写的数据类型。

例如,我有:

typedef struct Point3D
{
    char id[50];
    double x;
    double y;
    double z;   
    Point3D;
}

输入输出功能正常。

但问题如下: Point3D 的每个 id 都必须是唯一的(并且可以为 NULL),所以我决定在这个字段 id 上创建一个唯一索引,但这可能吗?

我的想法是这样的:

CREATE UNIQUE INDEX test_point3d_idx ON test_point3d (( getID(columname) ));

其中 getID 返回列名的字段 ID。

但是我需要实现getID,我真的被挡住了。

有什么建议吗?

最佳答案

Postgres 手册部分“Interfacing Extensions To Indexes”解释了用户定义类型(如 Point3D)的索引。这需要相当多的工作。我不知道任何捷径。

与您的问题无关:您确定需要这种 C 语言 Point3D 数据类型吗?这种数据类型定义中的错误可能是“confuse or even crash the server”。我认为这同样适用于支持它的 C 语言运算符函数。

您能否创建包含四列的表格,每个列对应一个 Point3D 字段?否则,您是否可以放弃 C 而使用简单的 CREATE TYPE point3d AS (i​​d char(50), x float8, y float8, z float8)?也许不是,但值得一试......

关于c - PostgreSQL - 创建索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2685550/

相关文章:

c - 是否可以使用 epoll,以及将 epoll 与 Netmap 一起使用来加速是否有意义?

c# - 转换方法。 "The specified method on the type cannot be translated into a LINQ to Entities store expression"

python - 如何在Pycharm Windows 中解决 "django.db.utils.OperationalError: FATAL: password authentication failed for user "Oeloun-pc""?

mysql - 是否需要再次索引 b,因为它已经是主目录下的 a

c - 在 c 中的消息队列上进行类型转换

android - 如何在编译android内核期间修复函数的隐式声明

c - 汇编、机器码、字节码和操作码之间的实际关系是什么?

postgresql - 改进 postgresql select 请求执行时间

ruby-on-rails - 轮胎+ Elasticsearch -强制导入

mysql索引大小和重复问题