Re: [SQL] TRUNCATE TABLE corrupts pg_class.relfilenode =pg_attrdef.pg_attrdef
| От | Sebastien FLAESCH |
|---|---|
| Тема | Re: [SQL] TRUNCATE TABLE corrupts pg_class.relfilenode =pg_attrdef.pg_attrdef |
| Дата | |
| Msg-id | 291ca3cf-79af-c161-4213-182c35e43fe6@4js.com обсуждение |
| Ответ на | [SQL] TRUNCATE TABLE corrupts pg_class.relfilenode = pg_attrdef.pg_attrdef (Sebastien FLAESCH <sf@4js.com>) |
| Ответы |
Re: [SQL] TRUNCATE TABLE corrupts pg_class.relfilenode =pg_attrdef.pg_attrdef
|
| Список | pgsql-sql |
Seems that the correct join condition should be:
(pg_class.oid = pg_attrdef.adrelid)
I don't know why we have used pg_class.relfilenode...
So this should be the correct SELECT statement:
test1=> select a.adsrc from pg_class p join pg_attrdef a on (p.oid = a.adrelid) where lower(p.relname) =
lower('mytab'); adsrc
------------------------------------- nextval('mytab_pkey_seq'::regclass)
(1 row)
Can someone confirm?
Thanks!
Seb
On 05/22/2017 12:51 PM, Sebastien FLAESCH wrote:
> Hi all,
>
> Testing with Postgresql 9.6rc1 (but also detected with prior versions):
>
> It is normal that a TRUNCATE TABLE statement changes the table/sequence relation in pg_attrdef?
>
> test1=> create table mytab ( pkey serial, name varchar(10) );
> test1=> select a.adsrc from pg_class p join pg_attrdef a on (p.relfilenode = a.adrelid) where lower(p.relname) =
lower('mytab');
> adsrc
> -------------------------------------
> nextval('mytab_pkey_seq'::regclass)
> (1 row)
>
> test1=> truncate table mytab;
> TRUNCATE TABLE
> test1=> select a.adsrc from pg_class p join pg_attrdef a on (p.relfilenode = a.adrelid) where lower(p.relname) =
lower('mytab');
> adsrc
> -------
> (0 rows)
>
> test1=> select adrelid, adsrc from pg_attrdef where adsrc like '%mytab%';
> adrelid | adsrc
> ---------+-------------------------------------
> 6904163 | nextval('mytab_pkey_seq'::regclass)
> (1 row)
>
>
> Are we mis-using the condition (p.relfilenode = a.adrelid) in the first SELECT?
>
> How can we easily check if a table is defined with a SERIAL type?
>
> Thanks!
> Seb
>
>
В списке pgsql-sql по дате отправления: