Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ea7a167

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

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
@@ -1839,7 +1839,7 @@ describeOneTableDetails(const char *schemaname,
18391839
{
18401840
/* use "pretty" mode for expression to avoid excessive parentheses */
18411841
appendPQExpBufferStr(&buf,
1842-
",\n (SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid, true) for 128)"
1842+
",\n (SELECT pg_catalog.pg_get_expr(d.adbin, d.adrelid, true)"
18431843
"\n FROM pg_catalog.pg_attrdef d"
18441844
"\n WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef)"
18451845
",\n a.attnotnull");
@@ -2042,7 +2042,8 @@ describeOneTableDetails(const char *schemaname,
20422042
{
20432043
char *identity;
20442044
char *generated;
2045-
char *default_str = "";
2045+
char *default_str;
2046+
bool mustfree = false;
20462047

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

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

2066-
printTableAddCell(&cont, default_str, false, generated[0] ? true : false);
2070+
printTableAddCell(&cont, default_str, false, mustfree);
20672071
}
20682072

20692073
/* Info for index columns */

0 commit comments

Comments
 (0)