use of postgres reg* datatypes in user tables?

Поиск
Список
Период
Сортировка
Искать

use of postgres reg* datatypes in user tables?

От:
plsqlvids01 plsqlvids01 <plsqlvids01@gmail.com>
Дата:
What is the use of postgres regclass datatype in user tables? When would one want to use them when regular data types are available? If any tables have these data types, since pg_upgrade would fail, what data types should those be converted to?

```
postgres=> select version();
                                                 version                                                  
----------------------------------------------------------------------------------------------------------
 PostgreSQL 14.11 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 7.3.1 20180712 (Red Hat 7.3.1-12), 64-bit
(1 row)

\dT pg_catalog.reg*
                        List of data types
   Schema   │     Name      │             Description              
════════════╪═══════════════╪══════════════════════════════════════
 pg_catalog │ regclass      │ registered class
 pg_catalog │ regcollation  │ registered collation
 pg_catalog │ regconfig     │ registered text search configuration
 pg_catalog │ regdictionary │ registered text search dictionary
 pg_catalog │ regnamespace  │ registered namespace
 pg_catalog │ regoper       │ registered operator
 pg_catalog │ regoperator   │ registered operator (with args)
 pg_catalog │ regproc       │ registered procedure
 pg_catalog │ regprocedure  │ registered procedure (with args)
 pg_catalog │ regrole       │ registered role
 pg_catalog │ regtype       │ registered type
(11 rows)

postgres=> create table t1 (c1 int, c2 regclass);
CREATE TABLE
postgres=> \d t1;
               Table "public.t1"
 Column |   Type   | Collation | Nullable | Default
--------+----------+-----------+----------+---------
 c1     | integer  |           |          |
 c2     | regclass |           |          |

postgres=> insert into t1 values(1,1);
INSERT 0 1
postgres=> insert into t1 values(2,'2');
INSERT 0 1
postgres=> insert into t1 values(3,'3'::int);
INSERT 0 1
postgres=> insert into t1 values(4,'4'::text);
ERROR:  relation "4" does not exist
postgres=> select * from t1;
 c1 | c2
----+----
  1 | 1
  2 | 2
  3 | 3
(3 rows)
```
What kind of data does these data types store - numbers or text? In above example am able to insert it as number as well as character '2'?

Re: use of postgres reg* datatypes in user tables?

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
plsqlvids01 plsqlvids01  writes:
> What is the use of postgres regclass datatype in user tables? When would
> one want to use them when regular data types are available? If any tables
> have these data types, since pg_upgrade would fail, what data types should
> those be converted to?

Indeed, storing reg* types in user tables isn't particularly
recommended because of the pg_upgrade problem.  However, casting
to a reg* type is plenty useful in queries on the system catalogs.
There is more info and examples in the manual:

https://www.postgresql.org/docs/current/datatype-oid.html

			regards, tom lane


Re: use of postgres reg* datatypes in user tables?

От:
"David G. Johnston" <david.g.johnston@gmail.com>
Дата:
On Sunday, August 18, 2024, plsqlvids01 plsqlvids01 <plsqlvids01@gmail.com> wrote:
What kind of data does these data types store - numbers or text?



They are aliases for oid.
 
David J.

FAQ