-- psql -tA < export.sql | tr '|' ''

\set SESSIONID 79109

select
	sessionid, returncode,
	'25|' || -- FormatVersion
	hnhls.hostname, -- %v ServerName
	hnhlh.hostname, -- %{Host}i Host
	ri.remoteip, -- %a
	au.authuser, -- %u
	hitdatetime, -- %{%F %T %z}t
	me.method || ' ' || pa.path || qu.query || ' ' || pr.protocol,
	fs.fileserved, -- %f
	hl.statusid, -- %>s
	hl.transsize, -- %B
	hl.timetoserve, -- %T
	hl.connection, -- %c
	rf.referer, -- %{Referer}i
	ua.useragent, -- %{User-Agent}i
	al.acceptlanguage, -- %{Accept-Language}i
	at.accept, -- %{Accept}i
	ae.acceptencoding, -- %{Accept-Encoding}i
	ac.acceptcharset, -- %{Accept-Charset}i
	vi.via, -- %{Via}i
	co.cookie, -- %{Cookie}i
	sc.setcookie, -- %{Set-Cookie}o
	ut.usertrack, -- &{cookie}n
	hl.connection, -- %c
	ct.contenttype -- %{Content-Type}o
from
	httplog hl,
	hostname hnhls, -- HostNameHttpLogServername
	hostname hnhlh, -- HostNameHttpLogHostname
	remoteip ri,
	authuser au,
	method me,
	path pa,
	query qu,
	protocol pr,
	fileserved fs,
	referer rf,
	useragent ua,
	acceptlanguage al,
	accept at, -- AccepT
	acceptencoding ae,
	acceptcharset ac,
	via vi,
	cookie co,
	setcookie sc,
	usertrack ut,
	contenttype ct
where
	hl.remoteipid = ri.remoteipid
	and hl.servernameid = hnhls.hostnameid
	and hl.hostid = hnhlh.hostnameid
	and hl.authuserid = au.authuserid
	and hl.methodid = me.methodid
	and hl.pathid = pa.pathid
	and hl.queryid = qu.queryid
	and hl.protocolid = pr.protocolid
	and hl.fileservedid = fs.fileservedid
	and hl.refererid = rf.refererid
	and hl.useragentid = ua.useragentid
	and hl.acceptlanguageid = al.acceptlanguageid
	and hl.acceptid = at.acceptid
	and hl.acceptencodingid = ae.acceptencodingid
	and hl.acceptcharsetid = ac.acceptcharsetid
	and hl.viaid = vi.viaid
	and hl.cookieid = co.cookieid
	and hl.setcookieid = sc.setcookieid
	and hl.usertrackid = ut.usertrackid
	and hl.contenttypeid = ct.contenttypeid
	--and returncode = 1
	--and hl.sessionid = :SESSIONID
	--and hl.contenttypeid=60
	and hl.returncode=2
order by
	httplogid desc
limit 10
;
