Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita0ef081

Browse files
committed
In psql's \d commands, don't truncate attribute default values.
Historically, psql has truncated the text of a column's defaultexpression at 128 characters. This is unlike any other behaviorin describe.c, and it's become particularly confusing now thatthe limit is only applied to the expression proper and not tothe "generated always as (...) stored" text that may get wrappedaround it.Excavation in our git history suggests that the original motivationfor this limit was not really to limit the display width (as I'd longsupposed), but to make it safe to use a fixed-width output buffer tostore the result. That implementation restriction is long gone ofcourse, but the limit remained. Let's just get rid of it.While here, rearrange the logic about when to free the output stringso that it's not so dependent on unstated assumptions about thepossible values of attidentity and attgenerated.Per bug #16743 from David Turon. Back-patch to v12 where GENERATEDcame in. (Arguably we could take it back further, but I'm hesitantto change the behavior of long-stable branches for this.)Discussion:https://postgr.es/m/16743-7b1bacc4af76e7ad@postgresql.org
1 parent7ef52b5 commita0ef081

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

‎src/bin/psql/describe.c‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,7 +1838,7 @@ describeOneTableDetails(const char *schemaname,
18381838
{
18391839
/* use "pretty" mode for expression to avoid excessive parentheses */
18401840
appendPQExpBufferStr(&buf,
1841-
",\n (SELECTsubstring(pg_catalog.pg_get_expr(d.adbin, d.adrelid, true) for 128)"
1841+
",\n (SELECT pg_catalog.pg_get_expr(d.adbin, d.adrelid, true)"
18421842
"\n FROM pg_catalog.pg_attrdef d"
18431843
"\n WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef)"
18441844
",\n a.attnotnull");
@@ -2041,7 +2041,8 @@ describeOneTableDetails(const char *schemaname,
20412041
{
20422042
char*identity;
20432043
char*generated;
2044-
char*default_str="";
2044+
char*default_str;
2045+
boolmustfree= false;
20452046

20462047
printTableAddCell(&cont,PQgetvalue(res,i,attcoll_col), false, false);
20472048

@@ -2057,12 +2058,15 @@ describeOneTableDetails(const char *schemaname,
20572058
elseif (identity[0]==ATTRIBUTE_IDENTITY_BY_DEFAULT)
20582059
default_str="generated by default as identity";
20592060
elseif (generated[0]==ATTRIBUTE_GENERATED_STORED)
2060-
default_str=psprintf("generated always as (%s) stored",PQgetvalue(res,i,attrdef_col));
2061+
{
2062+
default_str=psprintf("generated always as (%s) stored",
2063+
PQgetvalue(res,i,attrdef_col));
2064+
mustfree= true;
2065+
}
20612066
else
2062-
/* (note: above we cut off the 'default' string at 128) */
20632067
default_str=PQgetvalue(res,i,attrdef_col);
20642068

2065-
printTableAddCell(&cont,default_str, false,generated[0] ? true : false);
2069+
printTableAddCell(&cont,default_str, false,mustfree);
20662070
}
20672071

20682072
/* Info for index columns */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp