Skip to content

Instantly share code, notes, and snippets.

@hoehrmann
Created October 6, 2018 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoehrmann/44333096afac572d404534147729c102 to your computer and use it in GitHub Desktop.
Save hoehrmann/44333096afac572d404534147729c102 to your computer and use it in GitHub Desktop.
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
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment