Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Complex table formatting of SQL Query results using JSON formatting objects
-- styles for CPAN module Text::ANSITable
SELECT
time, priority, message
,
json_object(
'priority',
json_object(
'fgcolor',
CASE
WHEN priority IN ('ERROR', 'FATAL') THEN '#ff0000'
WHEN priority IN ('WARN') THEN '#ffff00'
WHEN priority IN ('INFO') THEN NULL
WHEN priority IN ('DEBUG', 'TRACE') THEN '#808080'
ELSE NULL
END
-- ,
-- 'bgcolor', NULL,
-- 'align', NULL,
-- 'valign', NULL,
-- 'formats', NULL
),
-- 'other_column',
-- json_object(
--
-- )
) AS __cell_style
,
json_object(
-- 'align', NULL,
-- 'valign', NULL,
-- 'height', NULL,
-- 'vpad', NULL,
-- 'tpad', NULL,
-- 'bpad', NULL,
-- 'fgcolor', NULL,
-- 'bgcolor', '#808080'
) AS __row_style
,
json_object(
'priority',
json_object(
-- 'align', NULL,
-- 'valign', NULL,
-- 'pad', NULL,
-- 'lpad', NULL,
-- 'rpad', NULL,
-- 'width', NULL,
-- 'formats', NULL,
-- 'fgcolor', NULL,
-- 'bgcolor', NULL,
-- 'type', NULL,
-- 'wrap', NULL
)
) AS __column_style
FROM
log
WHERE
priority IN ('ERROR', 'FATAL', 'WARN')
LIMIT 10
@hoehrmann

This comment has been minimized.

Copy link
Owner Author

commented Oct 7, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.