/* Keep the first quote, remove the second */
cp++;
}
- inquotes = !inquotes;
+ else
+ inquotes = !inquotes;
/* Collapse out quote at *cp */
memmove(cp, cp + 1, strlen(cp));
/* do not advance cp */
(3 rows)
-- ordered months in vertical header, ordered years in horizontal header
-SELECT EXTRACT(year FROM d) AS year, to_char(d,'Mon') AS "month name",
+SELECT EXTRACT(year FROM d) AS year, to_char(d,'Mon') AS """month"" name",
EXTRACT(month FROM d) AS month,
format('sum=%s avg=%s', sum(i), avg(i)::numeric(2,1))
FROM ctv_data
GROUP BY EXTRACT(year FROM d), to_char(d,'Mon'), EXTRACT(month FROM d)
ORDER BY month
-\crosstabview "month name" year format year
- month name | 2014 | 2015
-------------+-----------------+----------------
- Jan | | sum=3 avg=3.0
- Apr | | sum=10 avg=5.0
- Jul | sum=5 avg=5.0 | sum=4 avg=4.0
- Dec | sum=-3 avg=-3.0 |
+\crosstabview """month"" name" year format year
+ "month" name | 2014 | 2015
+--------------+-----------------+----------------
+ Jan | | sum=3 avg=3.0
+ Apr | | sum=10 avg=5.0
+ Jul | sum=5 avg=5.0 | sum=4 avg=4.0
+ Dec | sum=-3 avg=-3.0 |
(4 rows)
-- combine contents vertically into the same cell (V/H duplicates)
\crosstabview v "month name" 4 num
-- ordered months in vertical header, ordered years in horizontal header
-SELECT EXTRACT(year FROM d) AS year, to_char(d,'Mon') AS "month name",
+SELECT EXTRACT(year FROM d) AS year, to_char(d,'Mon') AS """month"" name",
EXTRACT(month FROM d) AS month,
format('sum=%s avg=%s', sum(i), avg(i)::numeric(2,1))
FROM ctv_data
GROUP BY EXTRACT(year FROM d), to_char(d,'Mon'), EXTRACT(month FROM d)
ORDER BY month
-\crosstabview "month name" year format year
+\crosstabview """month"" name" year format year
-- combine contents vertically into the same cell (V/H duplicates)
SELECT v, h, string_agg(c, E'\n') FROM ctv_data GROUP BY v, h ORDER BY 1,2,3