PostgreSQL 中的对象

发布于 2024-10-12 01:15:18 字数 112 浏览 1 评论 0原文

PostgreSQL 是第一个在关系系统中引入对象(序列化)的数据库……这就是我对对象和 PostgreSQL 的全部了解。我一直在做一些研究,但坦率地说没有发现任何好的东西。有没有关于这方面的好的文章/书籍?

PostgreSQL was the first database that introduced objects in relational systems (serialization)... and that is all what I know about objects and PostgreSQL. I have been doing some research, but frankly didn't find anything good. Is there any good articles/books about it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

杯别 2024-10-19 01:15:18

我不确定“在关系系统中引入对象”是什么意思。 PostgreSQL 确实有自定义类型,但这些与 OOP 完全不同。

AFAIK PostgreSQL 有时被称为“对象关系数据库”的唯一原因是因为它 支持表继承。然而,继承的主要用例实际上是表分区 ;性能限制意味着它对于实现“对象继承”不是很有用(即将发布的 PostgreSQL 9.1 版本将 消除其中一些限制)。

底线:这里没什么可看的,PostgreSQL 只是另一个关系数据库。

I'm not sure what you mean with "introducing objects in relational systems". PostgreSQL indeed has custom types, but those are nothing like OOP.

AFAIK the only reason why PostgreSQL is sometimes called an "object-relational database" is because it supports table inheritance. However, the main use case of inheritance has actually been table partitioning; the performance limitations mean that it's not very useful for implementing "object inheritance" (The upcoming PostgreSQL 9.1 release will remove some of these limitations).

Bottom line: Nothing to see here, PostgreSQL is just another relational database.

我做我的改变 2024-10-19 01:15:18

Postgres 7 文档的前言解释了为什么他们认为自己是对象关系的先驱概念(在 Postgres 8 及更高版本中,这一切都被改写/重组/删除)。 历史文档提供了更多详细信息。

The preface of the Postgres 7 documentation explains why they consider themselves as having pioneered object-relational concepts (in Postgres 8 and later, this got all rephrased/restructured/deleted). The history document gives more details.

情绪失控 2024-10-19 01:15:18

历史文献讲述了这个故事,但我很惊讶地看到这么多评论者提到了面向对象编程,这完全是一个单独的主题。

Postgres 最初是加州大学伯克利分校的一个突破性研究项目,由 Michael Stonebraker 领导,他之前在那里领导过 Ingres 开发项目。

对象关系数据库的经典示例涉及非表格数据的存储和检索,例如图像、音频、媒体等。Stonebreaker 预见了“数据爆炸”,特别是在二进制大型对象领域,例如图像、等等,并意识到传统的 RDBMS 无法胜任这项任务。

用于描述“愿景”的示例之一是需要根据数据本身的属性,而不仅仅是元数据(带有字符串“日落”的名称、标签等)来搜索图像数据库,查找日落图片.)。这个概念意味着革命性索引方法的发展,例如,基于主色谱(日落往往是红色、橙色)或其他属性,具体取决于数据类型。这些想法在 Illustra 产品中实现了商业化,该产品是原始 Postgres 团队工作的直接后代。

事实上,大多数 ORDBMS 功能都是从 Postgres 代码库中减去的,这就是我们今天所知的 PostgreSQL。从这个意义上来说,结论是正确的。甚至 PostgreSQL 也缺乏原始 Postgres 的 ORDBMS 方面。

那么,Oracle 中的对象呢?还是不在那儿。 RDBMS 中的 OOP?根本不是同一个话题。

The historical documents tell the tale, but I was surprised to see that so many commentors mentioned Object Oriented Programming, which is a separate subject entirely.

Postgres started at UC Berkeley as a ground breaking research project, led by Michael Stonebraker, who previously led the Ingres development project there.

The classic example of an Object Relational Database involved storage and retrieval of of non-tabular data, such as images, audio, media, etc. Stonebreaker forsaw the "data explosion", especially in the area of Binary Large Objects, such as images, etc., and realized that the traditional RDBMS was not up to the task.

One of the examples used to describe "the vision" was the need to search an image database, for pictures of sunsets, based on attributes of the data itself, not merely meta-data (names with the string "sunset", labels, etc.). The concept implied the development of revolutionary indexing methods, for example, based on dominant color spectrum (sunsets tend to be red, orange), or other attributes, depending on the data type. These ideas were commercialised in the Illustra product, which was a direct descendant of the original Postgres team's work.

In fact, most of the ORDBMS features were subtracted from the Postgres code base, which became that PostgreSQL that we know today. In that sense, the conclusion is correct. Even PostgreSQL lacks the ORDBMS aspect of the original Postgres.

So, objects in Oracle? Still not there. OOP in an RDBMS? Not the same topic at all.

游魂 2024-10-19 01:15:18

那么,从某些角度来看,Postgresql 可以将表实体视为复合类型,可以将其视为对象。

=> SELECT author FROM author;
|      author       |
+-------------------+
| "(1,'john doe')"  |
+-------------------+
| "(2,'Edgar')"     |
+-------------------+

与数组混合这可以非常强大

SELECT 
  author.id, 
  author.name,
  array_agg(post) AS posts
FROM 
  author 
    LEFT JOIN post ON 
        author.id = post.author_id 
GROUP BY 
  author.id;
| id |   name   |                  posts                 |
+----+----------+----------------------------------------+
|  1 | John Doe | {"(1,'first post')","(2,'new post')"}  |
+----+----------+----------------------------------------+
|  2 | Edgar    | {"(3,'Hello world')"}                  |
+----+----------+----------------------------------------+

当然它不是真正的 OOP。

Well, from some point of view, Postgresql can consider the tables entities as composite type which can be seen as objects.

=> SELECT author FROM author;
|      author       |
+-------------------+
| "(1,'john doe')"  |
+-------------------+
| "(2,'Edgar')"     |
+-------------------+

Mixed with Array this can be very powerful

SELECT 
  author.id, 
  author.name,
  array_agg(post) AS posts
FROM 
  author 
    LEFT JOIN post ON 
        author.id = post.author_id 
GROUP BY 
  author.id;
| id |   name   |                  posts                 |
+----+----------+----------------------------------------+
|  1 | John Doe | {"(1,'first post')","(2,'new post')"}  |
+----+----------+----------------------------------------+
|  2 | Edgar    | {"(3,'Hello world')"}                  |
+----+----------+----------------------------------------+

Of course it is not real OOP.

骷髅 2024-10-19 01:15:18

据我所知,第一个提供全面对象支持(具有用户定义类型、嵌套、主从关系等)的 RDBMS 是 Oracle。他们甚至在后来的版本中添加了继承,但在我看来这是一种矫枉过正。请参阅取自非常旧的 Oracle 客户端安装(超过 15 年)的示例 SQL 脚本。

drop view department;
drop type dept_t;
drop type emp_list;
drop type emp_t;
create or replace type emp_t as object (
  empno number,
  ename varchar2(80),
  sal   number
);    
/

create or replace type emp_list as table of emp_t;    
/

create or replace type dept_t as object (
  deptno number, 
  dname varchar2(80),
  loc   varchar2(80),
  employees emp_list
);    
/

create or replace view department of dept_t
with object OID (deptno)
as select deptno, dname, loc,
          cast(multiset(select empno, ename, sal 
                        from emp 
                        where emp.deptno = dept.deptno
                        ) as emp_list ) employees
     from dept;

create trigger department_ins
instead of insert on department
for each row 
declare
  emps emp_list;
  emp  emp_t;
begin
  -- Insert the master
  insert into dept( deptno, dname, loc ) 
  values (:new.deptno, :new.dname, :new.loc);

  -- Insert the details
  emps := :new.employees;
  for i in 1..emps.count loop
    emp := emps(i);
    insert into emp(deptno, empno, ename, sal)
    values (:new.deptno, emp.empno, emp.ename, emp.sal);
  end loop;
end;    
/

As far as I know, first RDBMS offering full scale objects support (the one with user defined types, nesting, master-detail relation etc.) was Oracle. They even added inheritance in later versions, but in my opinion it was an overkill. See example SQL script taken from very old Oracle client installation (more than 15 years old).

drop view department;
drop type dept_t;
drop type emp_list;
drop type emp_t;
create or replace type emp_t as object (
  empno number,
  ename varchar2(80),
  sal   number
);    
/

create or replace type emp_list as table of emp_t;    
/

create or replace type dept_t as object (
  deptno number, 
  dname varchar2(80),
  loc   varchar2(80),
  employees emp_list
);    
/

create or replace view department of dept_t
with object OID (deptno)
as select deptno, dname, loc,
          cast(multiset(select empno, ename, sal 
                        from emp 
                        where emp.deptno = dept.deptno
                        ) as emp_list ) employees
     from dept;

create trigger department_ins
instead of insert on department
for each row 
declare
  emps emp_list;
  emp  emp_t;
begin
  -- Insert the master
  insert into dept( deptno, dname, loc ) 
  values (:new.deptno, :new.dname, :new.loc);

  -- Insert the details
  emps := :new.employees;
  for i in 1..emps.count loop
    emp := emps(i);
    insert into emp(deptno, empno, ename, sal)
    values (:new.deptno, emp.empno, emp.ename, emp.sal);
  end loop;
end;    
/
叹沉浮 2024-10-19 01:15:18

正如 Martin v. Löwis 所提到的,旧 PostgreSQL 7 文档 在本主题中简单列出了以下 3 点:

  • 继承(表继承)
  • 数据类型(PostreSQL 支持 JSON、Array 和 hstore)
  • 函数

恕我直言,我猜这些功能在 PostgreSQL 在 80 年代引入时是最前沿的,但是,如今在其他数据库中广泛使用。虽然 PostgreSQL 仍在推销“对象”这个术语,但人们还是感到困惑。

As mentioned by Martin v. Löwis, the old PostgreSQL 7 document simply lists the following 3 points in this topic:

  • inheritance (table inheritance)
  • data types (PostreSQL supports JSON, Array and hstore)
  • functions

IMHO, I guess these features were cutting edge when PostgreSQL introduced them back in the 80s, which, however, are widely available in other databases nowadays. While PostgreSQL still marketing the term "object" and people are confused.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文