SQL,Postgres OID,它们是什么,为什么它们有用? [英] SQL, Postgres OIDs, What are they and why are they useful?

查看:4200
本文介绍了SQL,Postgres OID,它们是什么,为什么它们有用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  CREATE TABLE(
.. 。
)WITH(OIDS = FALSE);

我阅读了postgres提供的文档,我知道OOP对象标识符的概念,但我仍然不抓住,




  • 为什么这种标识符在数据库中有用?



解决方案

> OID基本上为每个行提供一个内置的全局唯一ID,包含在系统列(而不是用户空间列)中。这对于没有主键,有重复行等的表来说非常方便。例如,如果您有一个包含两个相同行的表,并且要删除这两个表中最早的表,则可以使用oid列。



根据我的经验,在大多数postgres支持的应用程序中通常不使用此功能(可能部分是因为它们是非标准的)和其使用基本上已弃用


在PostgreSQL 8.1中,default_with_oids默认为
off;



在用户表中使用OID是
,被认为是过时的,所以大多数
安装应该禁用这个
变量。
需要特定表的OID的应用程序
在创建
表时应该指定WITH OIDS。该变量可以是
,以便与不遵循此
行为的旧
应用程序兼容。



I am looking at some PostgreSQL table creation and I stumbled upon this:

CREATE TABLE (
...
) WITH ( OIDS = FALSE );

I read the documentation provided by postgres and I know the concept of object identifier from OOP but still I do not grasp,

  • why such identifier would be useful in a database?
  • to make queries shorter?
  • when should it be used?

解决方案

OIDs basically give you a built-in, globally unique id for every row, contained in a system column (as opposed to a user-space column). That's handy for tables where you don't have a primary key, have duplicate rows, etc. For example, if you have a table with two identical rows, and you want to delete the oldest of the two, you could do that using the oid column.

In my experience, the feature is generally unused in most postgres-backed applications (probably in part because they're non-standard), and their use is essentially deprecated:

In PostgreSQL 8.1 default_with_oids is off by default; in prior versions of PostgreSQL, it was on by default.

The use of OIDs in user tables is considered deprecated, so most installations should leave this variable disabled. Applications that require OIDs for a particular table should specify WITH OIDS when creating the table. This variable can be enabled for compatibility with old applications that do not follow this behavior.

这篇关于SQL,Postgres OID,它们是什么,为什么它们有用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆