psql: Improve \crosstabview error messages

This commit is contained in:
Peter Eisentraut 2016-06-24 01:08:08 -04:00
parent 562e449724
commit bd406af168
2 changed files with 4 additions and 3 deletions

View File

@ -122,7 +122,7 @@ PrintResultsInCrosstab(const PGresult *res)
if (PQresultStatus(res) != PGRES_TUPLES_OK) if (PQresultStatus(res) != PGRES_TUPLES_OK)
{ {
psql_error("\\crosstabview: query must return results to be shown in crosstab\n"); psql_error("\\crosstabview: statement did not return a result set\n");
goto error_return; goto error_return;
} }
@ -643,7 +643,8 @@ indexOfColumn(char *arg, const PGresult *res)
idx = atoi(arg) - 1; idx = atoi(arg) - 1;
if (idx < 0 || idx >= PQnfields(res)) if (idx < 0 || idx >= PQnfields(res))
{ {
psql_error("\\crosstabview: invalid column number: \"%s\"\n", arg); psql_error("\\crosstabview: column number %d is out of range 1..%d\n",
idx + 1, PQnfields(res));
return -1; return -1;
} }
} }

View File

@ -188,7 +188,7 @@ SELECT 1 as "22", 2 as b, 3 as "Foo"
-- error: bad column number -- error: bad column number
SELECT v,h,i,c FROM ctv_data SELECT v,h,i,c FROM ctv_data
\crosstabview 2 1 5 \crosstabview 2 1 5
\crosstabview: invalid column number: "5" \crosstabview: column number 5 is out of range 1..4
-- error: same H and V columns -- error: same H and V columns
SELECT v,h,i,c FROM ctv_data SELECT v,h,i,c FROM ctv_data
\crosstabview 2 h 4 \crosstabview 2 h 4