aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2020-11-25 16:19:25 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2020-11-25 16:19:25 -0500
commita0ef0817204dbbcb326b14071e827bf181cfa2cb (patch)
tree53046d504c6562a2645a24bcadcb25e8d8813fb8 /src
parent7ef52b5d5de42cdd7d29f6bce7d7a07a9d4c6345 (diff)
downloadpostgresql-a0ef0817204dbbcb326b14071e827bf181cfa2cb.tar.gz
postgresql-a0ef0817204dbbcb326b14071e827bf181cfa2cb.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/bin/psql/describe.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index d22e4d66c74..4bdf6ce965e 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -1838,7 +1838,7 @@ describeOneTableDetails(const char *schemaname,
{
/* use "pretty" mode for expression to avoid excessive parentheses */
appendPQExpBufferStr(&buf,
- ",\n (SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid, true) for 128)"
+ ",\n (SELECT pg_catalog.pg_get_expr(d.adbin, d.adrelid, true)"
"\n FROM pg_catalog.pg_attrdef d"
"\n WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef)"
",\n a.attnotnull");
@@ -2041,7 +2041,8 @@ describeOneTableDetails(const char *schemaname,
{
char *identity;
char *generated;
- char *default_str = "";
+ char *default_str;
+ bool mustfree = false;
printTableAddCell(&cont, PQgetvalue(res, i, attcoll_col), false, false);
@@ -2057,12 +2058,15 @@ describeOneTableDetails(const char *schemaname,
else if (identity[0] == ATTRIBUTE_IDENTITY_BY_DEFAULT)
default_str = "generated by default as identity";
else if (generated[0] == ATTRIBUTE_GENERATED_STORED)
- default_str = psprintf("generated always as (%s) stored", PQgetvalue(res, i, attrdef_col));
+ {
+ default_str = psprintf("generated always as (%s) stored",
+ PQgetvalue(res, i, attrdef_col));
+ mustfree = true;
+ }
else
- /* (note: above we cut off the 'default' string at 128) */
default_str = PQgetvalue(res, i, attrdef_col);
- printTableAddCell(&cont, default_str, false, generated[0] ? true : false);
+ printTableAddCell(&cont, default_str, false, mustfree);
}
/* Info for index columns */