TRUNCATE TABLE corrupts pg_class.relfilenode = pg_attrdef.pg_attrdef

From: Sebastien FLAESCH <sf(at)4js(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: TRUNCATE TABLE corrupts pg_class.relfilenode = pg_attrdef.pg_attrdef
Date: 2017-05-22 10:51:27
Message-ID: 66def74b-633e-65a0-cf44-4d486f15ebd9@4js.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Sebastien FLAESCH 2017-05-22 10:57:54 Re: TRUNCATE TABLE corrupts pg_class.relfilenode = pg_attrdef.pg_attrdef
Previous Message Thomas Kellerer 2017-05-22 06:30:50 Re: SQL conversion help