From: | plsqlvids01 plsqlvids01 <plsqlvids01(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | use of postgres reg* datatypes in user tables? |
Date: | 2024-08-19 06:08:48 |
Message-ID: | CAFsfSrs+_7Aie27FPB+HnH0vEeT3h=5ZJj7k=OWDYTGksmYPiw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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'?
From | Date | Subject | |
---|---|---|---|
Next Message | sud | 2024-08-19 07:48:18 | Insert query performance |
Previous Message | jian he | 2024-08-19 00:00:00 | Re: Emitting JSON to file using COPY TO |