-- ToughLog
-- remotehost rfc931 authuser [date] "request" status bytes
-- psql -tA < common_log_format.sql
SELECT
host(r.remoteip)::text
|| ' -' -- authname does not exist
|| ' '  || CASE LENGTH(au.authuser) WHEN 0 THEN '-' ELSE au.authuser END
|| ' [' || to_char(h.hitDateTime,'DD/Mon/YYYY:HH24:MI:SS +0000') || ']'
|| ' "' || m.method || ' ' || pa.path || q.query || ' ' || pr.protocol || '"'
|| ' '  || h.statusid
|| ' '  || h.TransSize
|| ' "' || CASE LENGTH(re.referer) WHEN 0 THEN '-' ELSE re.referer END || '"'
|| ' "' || CASE LENGTH(ua.useragent) WHEN 0 THEN '-' ELSE ua.useragent END || '"'
AS "Common Log Format - RFC 931"
FROM httplog h, remoteip r, authuser au, method m, path pa, query q, protocol pr, referer re, useragent ua
WHERE
      h.remoteipid = r.remoteipid
  AND h.authuserid = au.authuserid
  AND h.methodid = m.methodid
  AND h.pathid = pa.pathid
  AND h.queryid = q.queryid
  AND h.protocolid = pr.protocolid
  AND h.refererid = re.refererid
  AND h.useragentid = ua.useragentid
;
