博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
postgres 继承 Inheritance
阅读量:2342 次
发布时间:2019-05-10

本文共 1620 字,大约阅读时间需要 5 分钟。

In PostgreSQL, a table can inherit from zero or more other tables, and a query can reference either all rows of a table or all rows of a table plus all of its descendant tables.For example, the following query finds the names of all cities, including state capitals, that are located at an altitude over 500 feet:

CREATE TABLE cities (    name            text,    population      float,    altitude        int     -- in feet);CREATE TABLE capitals (    state           char(2)) INHERITS (cities);SELECT name, altitude    FROM cities    WHERE altitude > 500;

In some cases you might wish to know which table a particular row originated from. There is a system column called tableoid in each table which can tell you the originating table:

SELECT c.tableoid, c.name, c.altitudeFROM cities cWHERE c.altitude > 500; tableoid |   name    | altitude----------+-----------+----------   139793 | Las Vegas |     2174   139793 | Mariposa  |     1953   139798 | Madison   |      845

By doing a join with pg_class you can see the actual table names:

SELECT p.relname, c.name, c.altitudeFROM cities c, pg_class pWHERE c.altitude > 500 AND c.tableoid = p.oid;

Another way to get the same effect is to use the regclass pseudo-type, which will print the table OID symbolically:

SELECT c.tableoid::regclass, c.name, c.altitudeFROM cities cWHERE c.altitude > 500;

Inheritance does not automatically propagate data from INSERT or COPY commands to other tables in the inheritance hierarchy. In our example, the following INSERT statement will fail:

INSERT INTO cities (name, population, altitude, state)VALUES ('Albany', NULL, NULL, 'NY');

转载地址:http://yeyvb.baihongyu.com/

你可能感兴趣的文章
Camera Calibration and 3D Reconstruction
查看>>
OpenCV-Python] OpenCV 中摄像机标定和 3D 重构 部分 VII
查看>>
【计算机视觉】opencv靶标相机姿态解算2 根据四个特征点估计相机姿态 及 实时位姿估计与三维重建相机姿态
查看>>
关于OpenNI2和OpenCV2的那些事——获取三维点云数据并用OpenGL表示
查看>>
一起做RGB-D SLAM (6)
查看>>
利用matlab摄像机标定
查看>>
Ubuntu下安装Matlab并破解
查看>>
camodocal 编译依赖库的问题
查看>>
c/c++: c++函数返回类型什么情况带const
查看>>
const引用返回值
查看>>
三维坐标变换——旋转矩阵与旋转向量
查看>>
视觉里程计设计与实现
查看>>
视觉里程计研究小结
查看>>
vo类总结
查看>>
solvepnp三维位姿估算
查看>>
旋转矩阵、欧拉角、四元数理论及其转换关系
查看>>
机器人笛卡尔空间坐标系轨迹规划的研究
查看>>
视觉SLAM——第三章 Eigen几何模块Geometry使用 四元素 欧式变换矩阵
查看>>
半闲居士视觉SLAM十四讲笔记(3)三维空间刚体运动 - part 5 Eigen_Geometry、Pangolin安装
查看>>
程序员的绘图利器 — Gnuplot
查看>>