作者:瀚高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)
有点意思。