postgresql一个有趣的现象

作者:瀚高PG实验室 (Highgo PG Lab)-徐云鹤
在postgresql中线创建一张表,

highgo=# create table abcd (int int);
CREATE TABLE

然后再创建一张表,列的数据类型使用刚刚创建的表名。

	highgo=# create table abcde (abcd abcd);
	CREATE TABLE

创建成功了。
创建的每一个表都会同时生成同名的类型?

highgo=# select * from pg_type where typname='abcd';
 typname | typnamespace | typowner | typlen | typbyval | typtype | typcategory | typispreferred | typisdefined | typdelim | typrelid | typelem | typarray | typinput  |
 typoutput  | typreceive  |   typsend   | typmodin | typmodout | typanalyze | typalign | typstorage | typnotnull | typbasetype | typtypmod | typndims | typcollation | 
typdefaultbin | typdefault | typacl 
---------+--------------+----------+--------+----------+---------+-------------+----------------+--------------+----------+----------+---------+----------+-----------+
------------+-------------+-------------+----------+-----------+------------+----------+------------+------------+-------------+-----------+----------+--------------+-
--------------+------------+--------
 abcd    |         2200 |       10 |     -1 | f        | c       | C           | f              | t            | ,        |    17993 |       0 |    17994 | record_in |
 record_out | record_recv | record_send | -        | -         | -          | d        | x          | f          |           0 |        -1 |        0 |            0 | 
          |            | 
(1 row)

尝试删除此表。

highgo=# drop table abcd;
错误:  2BP01: 无法删除 表 abcd 因为有其它对象倚赖它
DETAIL:  表 abcde 字段 abcd 倚赖于 类型 abcd
HINT:  使用 DROP .. CASCADE 把倚赖对象一并删除.
highgo=# drop table abcd cascade;
注意:  00000: 递归删除 表 abcde 字段 abcd
DROP TABLE
highgo=# select * from abcde;
--
(0 rows)

厉害了word哥。
查查还有这个类型不?

highgo=# select * from pg_type where typname='abcd';
 typname | typnamespace | typowner | typlen | typbyval | typtype | typcategory | typispreferred | typisdefined | typdelim | typrelid | typelem | typarray | typinput | 
typoutput | typreceive | typsend | typmodin | typmodout | typanalyze | typalign | typstorage | typnotnull | typbasetype | typtypmod | typndims | typcollation | typdefa
ultbin | typdefault | typacl 
---------+--------------+----------+--------+----------+---------+-------------+----------------+--------------+----------+----------+---------+----------+----------+-
----------+------------+---------+----------+-----------+------------+----------+------------+------------+-------------+-----------+----------+--------------+--------
-------+------------+--------
(0 rows)

有点意思。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值