Strange presentaion related to inheritance in \d+
От | Kyotaro Horiguchi |
---|---|
Тема | Strange presentaion related to inheritance in \d+ |
Дата | |
Msg-id | 20230828.161658.1184657435220765047.horikyota.ntt@gmail.com обсуждение исходный текст |
Ответы |
Re: Strange presentaion related to inheritance in \d+
|
Список | pgsql-hackers |
While translating a message, I found a questionable behavior in \d+, introduced by a recent commit b0e96f3119. In short, the current code hides the constraint's origin when "NO INHERIT" is used. For these tables: create table p (a int, b int not null default 0); create table c1 (a int, b int not null default 1) inherits (p); The output from "\d+ c1" contains the lines: > Not-null constraints: > "c1_b_not_null" NOT NULL "b" *(local, inherited)* But with these tables: create table p (a int, b int not null default 0); create table c1 (a int, b int not null NO INHERIT default 1) inherits (p); I get: > Not-null constraints: > "c1_b_not_null" NOT NULL "b" *NO INHERIT* Here, "NO INHERIT" is mapped from connoinherit, and conislocal and "coninhcount <> 0" align with "local" and "inherited". For a clearer picuture, those values for c1 are as follows. =# SELECT co.conname, at.attname, co.connoinherit, co.conislocal, co.coninhcount FROM pg_catalog.pg_constraint co JOIN pg_catalog.pg_attributeat ON (at.attnum = co.conkey[1]) WHERE co.contype = 'n' AND co.conrelid = 'c1'::pg_catalog.regclassAND at.attrelid = 'c1'::pg_catalog.regclass ORDER BY at.attnum; conname | attname | connoinherit | conislocal | coninhcount ---------------+---------+--------------+------------+------------- c1_b_not_null | b | t | t | 1 It feels off to me, but couldn't find any discussion about it. Is it the intended behavior? I believe it's more appropriate to show the origins even when specifed as NO INHERIT. ====== If not so, the following change might be possible, which is quite simple. > Not-null constraints: > "c1_b_not_null" NOT NULL "b" NO INHERIT(local, inherited) However, it looks somewhat strange as the information in parentheses is not secondary to "NO INHERIT". Thus, perhaps a clearer or more proper representation would be: > "c1_b_not_null" NOT NULL "b" (local, inherited, not inheritable) That being said, I don't come up with a simple way to do this for now.. (Note that we need to translate the puctuations and the words.) There's no need to account for all combinations. "Local" and "inherited" don't be false at the same time and the combination (local & !inherited) is not displayed. Given these factors, we're left with 6 possible combinations, which I don't think aren't worth the hassle: (local, inherited, not inheritable) (inherited, not inheritable) # I didn't figure out how to cause this. (not inheritable) (local, inherited) (inherited) "" (empty string, means local) A potential solution that comes to mind is presenting the attributes in a space sparated list after a colon as attached. (Honestly, I'm not fond of the format and the final term, though.) > "c1_b_not_null" NOT NULL "b": local inherited uninheritable In 0001, I did wonder about hiding "local" when it's not inherited, but this behavior rfollows existing code. In 0002, I'm not completely satisfied with the location, but standard regression test suite seems more suitable for this check than the TAP test suite used for testing psql. regards. -- Kyotaro Horiguchi NTT Open Source Software Center
Вложения
В списке pgsql-hackers по дате отправления: