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

Commit 5ac6b76

Browse files
committed
Attempt to standardize formatting of psql queries.
Most queries end with a backslash, but not a newline, so try to standardize on that, for the convenience of people using psql -E to extract queries. Josh Kupershmidt, reviewed by Merlin Moncure.
1 parent 6e6cc59 commit 5ac6b76

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

src/bin/psql/describe.c

+24-24
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ describeOneTableDetails(const char *schemaname,
11591159
"c.relpersistence\n"
11601160
"FROM pg_catalog.pg_class c\n "
11611161
"LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1162-
"WHERE c.oid = '%s'\n",
1162+
"WHERE c.oid = '%s';",
11631163
(verbose ?
11641164
"pg_catalog.array_to_string(c.reloptions || "
11651165
"array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
@@ -1175,7 +1175,7 @@ describeOneTableDetails(const char *schemaname,
11751175
"CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END\n"
11761176
"FROM pg_catalog.pg_class c\n "
11771177
"LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1178-
"WHERE c.oid = '%s'\n",
1178+
"WHERE c.oid = '%s';",
11791179
(verbose ?
11801180
"pg_catalog.array_to_string(c.reloptions || "
11811181
"array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
@@ -1190,7 +1190,7 @@ describeOneTableDetails(const char *schemaname,
11901190
"%s, c.reltablespace\n"
11911191
"FROM pg_catalog.pg_class c\n "
11921192
"LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1193-
"WHERE c.oid = '%s'\n",
1193+
"WHERE c.oid = '%s';",
11941194
(verbose ?
11951195
"pg_catalog.array_to_string(c.reloptions || "
11961196
"array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
@@ -1203,7 +1203,7 @@ describeOneTableDetails(const char *schemaname,
12031203
"SELECT relchecks, relkind, relhasindex, relhasrules, "
12041204
"reltriggers <> 0, relhasoids, "
12051205
"%s, reltablespace\n"
1206-
"FROM pg_catalog.pg_class WHERE oid = '%s'",
1206+
"FROM pg_catalog.pg_class WHERE oid = '%s';",
12071207
(verbose ?
12081208
"pg_catalog.array_to_string(reloptions, E', ')" : "''"),
12091209
oid);
@@ -1214,7 +1214,7 @@ describeOneTableDetails(const char *schemaname,
12141214
"SELECT relchecks, relkind, relhasindex, relhasrules, "
12151215
"reltriggers <> 0, relhasoids, "
12161216
"'', reltablespace\n"
1217-
"FROM pg_catalog.pg_class WHERE oid = '%s'",
1217+
"FROM pg_catalog.pg_class WHERE oid = '%s';",
12181218
oid);
12191219
}
12201220
else
@@ -1223,7 +1223,7 @@ describeOneTableDetails(const char *schemaname,
12231223
"SELECT relchecks, relkind, relhasindex, relhasrules, "
12241224
"reltriggers <> 0, relhasoids, "
12251225
"'', ''\n"
1226-
"FROM pg_catalog.pg_class WHERE oid = '%s'",
1226+
"FROM pg_catalog.pg_class WHERE oid = '%s';",
12271227
oid);
12281228
}
12291229

@@ -1265,7 +1265,7 @@ describeOneTableDetails(const char *schemaname,
12651265
{
12661266
printfPQExpBuffer(&buf, "SELECT * FROM %s", fmtId(schemaname));
12671267
/* must be separate because fmtId isn't reentrant */
1268-
appendPQExpBuffer(&buf, ".%s", fmtId(relationname));
1268+
appendPQExpBuffer(&buf, ".%s;", fmtId(relationname));
12691269

12701270
res = PSQLexec(buf.data, false);
12711271
if (!res)
@@ -1299,7 +1299,7 @@ describeOneTableDetails(const char *schemaname,
12991299
appendPQExpBuffer(&buf, ",\n a.attstorage, pg_catalog.col_description(a.attrelid, a.attnum)");
13001300
appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_attribute a");
13011301
appendPQExpBuffer(&buf, "\nWHERE a.attrelid = '%s' AND a.attnum > 0 AND NOT a.attisdropped", oid);
1302-
appendPQExpBuffer(&buf, "\nORDER BY a.attnum");
1302+
appendPQExpBuffer(&buf, "\nORDER BY a.attnum;");
13031303

13041304
res = PSQLexec(buf.data, false);
13051305
if (!res)
@@ -1394,7 +1394,7 @@ describeOneTableDetails(const char *schemaname,
13941394
PGresult *result;
13951395

13961396
printfPQExpBuffer(&buf,
1397-
"SELECT pg_catalog.pg_get_viewdef('%s'::pg_catalog.oid, true)",
1397+
"SELECT pg_catalog.pg_get_viewdef('%s'::pg_catalog.oid, true);",
13981398
oid);
13991399
result = PSQLexec(buf.data, false);
14001400
if (!result)
@@ -1509,7 +1509,7 @@ describeOneTableDetails(const char *schemaname,
15091509
"pg_catalog.pg_get_expr(i.indpred, i.indrelid, true)\n"
15101510
"FROM pg_catalog.pg_index i, pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_am a\n"
15111511
"WHERE i.indexrelid = c.oid AND c.oid = '%s' AND c.relam = a.oid\n"
1512-
"AND i.indrelid = c2.oid",
1512+
"AND i.indrelid = c2.oid;",
15131513
oid);
15141514

15151515
result = PSQLexec(buf.data, false);
@@ -1580,7 +1580,7 @@ describeOneTableDetails(const char *schemaname,
15801580
printfPQExpBuffer(&buf,
15811581
"SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true))\n"
15821582
"FROM pg_catalog.pg_rewrite r\n"
1583-
"WHERE r.ev_class = '%s' AND r.rulename != '_RETURN' ORDER BY 1",
1583+
"WHERE r.ev_class = '%s' AND r.rulename != '_RETURN' ORDER BY 1;",
15841584
oid);
15851585
result = PSQLexec(buf.data, false);
15861586
if (!result)
@@ -1637,7 +1637,7 @@ describeOneTableDetails(const char *schemaname,
16371637
" LEFT JOIN pg_catalog.pg_constraint con ON (conrelid = i.indrelid AND conindid = i.indexrelid AND contype IN ('p','u','x'))\n");
16381638
appendPQExpBuffer(&buf,
16391639
"WHERE c.oid = '%s' AND c.oid = i.indrelid AND i.indexrelid = c2.oid\n"
1640-
"ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname",
1640+
"ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname;",
16411641
oid);
16421642
result = PSQLexec(buf.data, false);
16431643
if (!result)
@@ -1717,7 +1717,7 @@ describeOneTableDetails(const char *schemaname,
17171717
"SELECT r.conname, "
17181718
"pg_catalog.pg_get_constraintdef(r.oid, true)\n"
17191719
"FROM pg_catalog.pg_constraint r\n"
1720-
"WHERE r.conrelid = '%s' AND r.contype = 'c'\nORDER BY 1",
1720+
"WHERE r.conrelid = '%s' AND r.contype = 'c'\nORDER BY 1;",
17211721
oid);
17221722
result = PSQLexec(buf.data, false);
17231723
if (!result)
@@ -1748,7 +1748,7 @@ describeOneTableDetails(const char *schemaname,
17481748
"SELECT conname,\n"
17491749
" pg_catalog.pg_get_constraintdef(r.oid, true) as condef\n"
17501750
"FROM pg_catalog.pg_constraint r\n"
1751-
"WHERE r.conrelid = '%s' AND r.contype = 'f' ORDER BY 1",
1751+
"WHERE r.conrelid = '%s' AND r.contype = 'f' ORDER BY 1;",
17521752
oid);
17531753
result = PSQLexec(buf.data, false);
17541754
if (!result)
@@ -1779,7 +1779,7 @@ describeOneTableDetails(const char *schemaname,
17791779
"SELECT conname, conrelid::pg_catalog.regclass,\n"
17801780
" pg_catalog.pg_get_constraintdef(c.oid, true) as condef\n"
17811781
"FROM pg_catalog.pg_constraint c\n"
1782-
"WHERE c.confrelid = '%s' AND c.contype = 'f' ORDER BY 1",
1782+
"WHERE c.confrelid = '%s' AND c.contype = 'f' ORDER BY 1;",
17831783
oid);
17841784
result = PSQLexec(buf.data, false);
17851785
if (!result)
@@ -1812,7 +1812,7 @@ describeOneTableDetails(const char *schemaname,
18121812
"SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true)), "
18131813
"ev_enabled\n"
18141814
"FROM pg_catalog.pg_rewrite r\n"
1815-
"WHERE r.ev_class = '%s' ORDER BY 1",
1815+
"WHERE r.ev_class = '%s' ORDER BY 1;",
18161816
oid);
18171817
}
18181818
else
@@ -1821,7 +1821,7 @@ describeOneTableDetails(const char *schemaname,
18211821
"SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true)), "
18221822
"'O'::char AS ev_enabled\n"
18231823
"FROM pg_catalog.pg_rewrite r\n"
1824-
"WHERE r.ev_class = '%s' ORDER BY 1",
1824+
"WHERE r.ev_class = '%s' ORDER BY 1;",
18251825
oid);
18261826
}
18271827
result = PSQLexec(buf.data, false);
@@ -1927,7 +1927,7 @@ describeOneTableDetails(const char *schemaname,
19271927
" (SELECT 1 FROM pg_catalog.pg_depend d "
19281928
" JOIN pg_catalog.pg_constraint c ON (d.refclassid = c.tableoid AND d.refobjid = c.oid) "
19291929
" WHERE d.classid = t.tableoid AND d.objid = t.oid AND d.deptype = 'i' AND c.contype = 'f'))");
1930-
appendPQExpBuffer(&buf, "\nORDER BY 1");
1930+
appendPQExpBuffer(&buf, "\nORDER BY 1;");
19311931

19321932
result = PSQLexec(buf.data, false);
19331933
if (!result)
@@ -2035,7 +2035,7 @@ describeOneTableDetails(const char *schemaname,
20352035
"SELECT s.srvname\n"
20362036
"FROM pg_catalog.pg_foreign_table f,\n"
20372037
" pg_catalog.pg_foreign_server s\n"
2038-
"WHERE f.ftrelid = %s AND s.oid = f.ftserver",
2038+
"WHERE f.ftrelid = %s AND s.oid = f.ftserver;",
20392039
oid);
20402040
result = PSQLexec(buf.data, false);
20412041
if (!result)
@@ -2053,7 +2053,7 @@ describeOneTableDetails(const char *schemaname,
20532053
}
20542054

20552055
/* print inherited tables */
2056-
printfPQExpBuffer(&buf, "SELECT c.oid::pg_catalog.regclass FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i WHERE c.oid=i.inhparent AND i.inhrelid = '%s' ORDER BY inhseqno", oid);
2056+
printfPQExpBuffer(&buf, "SELECT c.oid::pg_catalog.regclass FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i WHERE c.oid=i.inhparent AND i.inhrelid = '%s' ORDER BY inhseqno;", oid);
20572057

20582058
result = PSQLexec(buf.data, false);
20592059
if (!result)
@@ -2215,7 +2215,7 @@ add_tablespace_footer(printTableContent *const cont, char relkind,
22152215
initPQExpBuffer(&buf);
22162216
printfPQExpBuffer(&buf,
22172217
"SELECT spcname FROM pg_catalog.pg_tablespace\n"
2218-
"WHERE oid = '%u'", tablespace);
2218+
"WHERE oid = '%u';", tablespace);
22192219
result = PSQLexec(buf.data, false);
22202220
if (!result)
22212221
return;
@@ -2424,7 +2424,7 @@ listDbRoleSettings(const char *pattern, const char *pattern2)
24242424
NULL, "pg_roles.rolname", NULL, NULL);
24252425
processSQLNamePattern(pset.db, &buf, pattern2, havewhere, false,
24262426
NULL, "pg_database.datname", NULL, NULL);
2427-
appendPQExpBufferStr(&buf, "ORDER BY role, database");
2427+
appendPQExpBufferStr(&buf, "ORDER BY role, database;");
24282428
}
24292429
else
24302430
{
@@ -3170,7 +3170,7 @@ describeOneTSParser(const char *oid, const char *nspname, const char *prsname)
31703170
" p.prslextype::pg_catalog.regproc, \n"
31713171
" pg_catalog.obj_description(p.prslextype, 'pg_proc') \n"
31723172
" FROM pg_catalog.pg_ts_parser p \n"
3173-
" WHERE p.oid = '%s' \n",
3173+
" WHERE p.oid = '%s';",
31743174
gettext_noop("Start parse"),
31753175
gettext_noop("Method"),
31763176
gettext_noop("Function"),
@@ -3531,7 +3531,7 @@ describeOneTSConfig(const char *oid, const char *nspname, const char *cfgname,
35313531
"FROM pg_catalog.pg_ts_config AS c, pg_catalog.pg_ts_config_map AS m \n"
35323532
"WHERE c.oid = '%s' AND m.mapcfg = c.oid \n"
35333533
"GROUP BY m.mapcfg, m.maptokentype, c.cfgparser \n"
3534-
"ORDER BY 1",
3534+
"ORDER BY 1;",
35353535
gettext_noop("Token"),
35363536
gettext_noop("Dictionaries"),
35373537
oid);

0 commit comments

Comments
 (0)