An interesting phenomenon of postgresql

Keywords: PostgreSQL

Create a table in the postgresql line,

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

Then create a table with the data type of the column using the table name you just created.

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

Created successfully.
Will each created table generate a type with the same name?

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)

Try to delete this table.

highgo=# drop table abcd;
Error: 2BP01: cannot delete table abcd because it is dependent on another object
 DETAIL: table abcd field abcd depends on type abcd
 HINT: use drop.. cascade to delete the dependent objects
highgo=# drop table abcd cascade;
Note: 00000: recursively delete table abcd field abcd
DROP TABLE
highgo=# select * from abcde;
--
(0 rows)

I'm so good at word.
Is there another type?

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)

I little interesting.

By Xu Yunhe

Posted by dinku33 on Fri, 01 May 2020 07:33:23 -0700