Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1urVEp-007LvI-PL for pgsql-general@arkaria.postgresql.org; Thu, 28 Aug 2025 05:31:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1urVEp-001M7n-0Y for pgsql-general@arkaria.postgresql.org; Thu, 28 Aug 2025 05:31:55 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1urVEo-001M7f-Ho for pgsql-general@lists.postgresql.org; Thu, 28 Aug 2025 05:31:55 +0000 Received: from mail-ot1-x32a.google.com ([2607:f8b0:4864:20::32a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1urVEm-0028af-1U for pgsql-general@postgresql.org; Thu, 28 Aug 2025 05:31:53 +0000 Received: by mail-ot1-x32a.google.com with SMTP id 46e09a7af769-74526ca7d64so496993a34.2 for ; Wed, 27 Aug 2025 22:31:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1756359112; x=1756963912; darn=postgresql.org; h=cc:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=aObTr4/pCkCWZJci33tzevUM2QRxJs/8DEEdaxJ0p74=; b=F3qLp3bm0i21gyjxBYAP4FZ5tpOOtRWzMDOuTkP2Q9JXQuutFnXXt49NYikN8tTxmq p//ypm+Z3zRGUTW5WxFiKUPtItU4IBRTsrGyFK/13qiRYtlgX662mQSOWgZC+5y5fheB vU6j5LOzGHONcc2N0F1p54oX3jFnkr/LSHHrwJ59YK7/35Oh5vbGXJm/8O0SVVeWGH00 y7dXHPF5PoOh+mMmj6Gkstdp/RHXkPoOhS76zgtLGyITXoATCvAvD/UsNz7uikqAIFO3 QIDHZtyvRz1OiKgoKZVAZf2lMWo7lbipZ5vWePmzhhk10dQC4NUTKq0ZU2DQcxjPdqDg 31yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756359112; x=1756963912; h=cc:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=aObTr4/pCkCWZJci33tzevUM2QRxJs/8DEEdaxJ0p74=; b=CjGU2VzoGfJI0Jq95uwXHnQCS0Nu2x/LSVPwz9Y1kPgWAKH1O+t4T9bWoFBPPRJza8 fA7WCJ4uvlVZzCUDlaX+B/stT7X5sSosZ/oB5r/e+WAejs89upLJIagPUC16yLWoL8dF WBBZgvx70Z4izXeYpeyZkigltesA7iuidVQGAnjrVhb0Kk2SKbwKwvxBIgS+aL7uwZmq HspbicH+DNP5nC9G1exkHIt2LEsHF9ugkYblszNQjqFh+svgMC9CVIUJ5LVYQR8sfH4G mXSJW74HBUmfHT8v4bHijqq3Kp2hKIEgwven5yVVyGx3Llhf7iDXo2vOzJDekP60JQpp 6ROw== X-Gm-Message-State: AOJu0YyzbdJmTQYhJsIxszc19VS9YrTM8Mx3yFmgGTFl/q/VQFgZTI0B pG8Ymi3d9lW6aPVPO3IuPM07Nk9EgWc7Z2c45JQccNGVlzt/+00X+1kL2LU0gGx1E43Jw20bOOS pdsy5Zoo/+6C3KAGGIc/aSxkMJVH4gYA750p2 X-Gm-Gg: ASbGncs/nuUxzt/K4c3m5q7dxpffTxcvgDnTyxtnXHmKa4EC2V6kOIX2HMJn9GdqcYE qrotcSwxkb/mEJYGRPu8opWvHHVIkzu24q3LXqli8GruTwOFlF3ug9SLyl13yaJXuNZlqNgPfkg Vmg+njwb1qXyeQMenFWpjpW+E9tDiDLDXw5aCO4Y4SujAg31tsNSKHTvY18yifpDh3X2ft+aDFx 9/Sh+E6 X-Google-Smtp-Source: AGHT+IHkBGWRr5/pEICHJUTyoe5b5NeY3y9nOANJp1B1vqTOvFE5m5jCu5nvLhbZQzddTadgeTb4El+mmNsO0tJbdro= X-Received: by 2002:a05:6808:80ad:b0:40b:711:377d with SMTP id 5614622812f47-43785216634mr9519459b6e.18.1756359112136; Wed, 27 Aug 2025 22:31:52 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Ron Johnson Date: Thu, 28 Aug 2025 01:31:41 -0400 X-Gm-Features: Ac12FXzV5prPpd39loZvyq_0SzhnXR98LO4QpivoDvbAGJRroHfYxGPUtJB71i8 Message-ID: Subject: Re: psql --html and to_char() Cc: pgsql-general Content-Type: multipart/alternative; boundary="000000000000fa1ee5063d663801" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000fa1ee5063d663801 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Aug 27, 2025 at 6:13=E2=80=AFPM Greg Sabino Mullane wrote: > On Wed, Aug 27, 2025 at 11:28=E2=80=AFAM Ron Johnson > wrote: > >> Is there a way around this, other than writing my own HTMLifier? >> > > Not unless your to_char() output can be coerced back into a numeric. (for > the archives sake, see fe_utils/print.c for the complete list of > right-aligned columns: int family, float, numeric, oid, xid, cid, and the > when-will-it-finally-die money type) > Easier to write a generic shell function. HTMLify_csv() { local -rn pFormats=3D"$1" local line local -a lFields printf '\n' read -r line IFS=3D'|' read -r -a lFields <<< "${line}" local -i lFldCnt=3D${#lFields[@]} printf '' for ((i=3D0; i<$lFldCnt; i++)); do printf '' ce= nter "${lFields[i]}"; done printf "\n" while IFS=3D read -r line do [[ $line =3D~ rows?\)$ ]] && { printf '\n' "$line"; continue; } IFS=3D'|' read -r -a lFields <<< "${line}" printf '' for ((i=3D0; i<$lFldCnt; i++)) do printf '' "${pFormats[i]}" "${lFields[i= ]}" done printf "\n" done printf '
%s
%s
%s
\n' } declare -a Formats=3D(right left) psql -XAc "select to_char(oid::integer, '99,999') as oid, datname from pg_database;" | HTMLify_csv Formats It requires an array that describes how you want each column aligned. --=20 Death to , and butter sauce. Don't boil me, I'm still alive. lobster! --000000000000fa1ee5063d663801 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Wed, Aug 27,= 2025 at 6:13=E2=80=AFPM Greg Sabino Mullane <htamfids@gmail.com> wrote:
On Wed, Aug= 27, 2025 at 11:28=E2=80=AFAM Ron Johnson <ronljohnsonjr@gmail.com> wrote:
Is there a way around this, other than writing my = own HTMLifier?

Not unless your = to_char() output can be coerced back into a numeric. (for the archives sake= , see fe_utils/print.c for the complete list of right-aligned columns: int = family, float, numeric, oid, xid, cid, and the when-will-it-finally-die mon= ey type)

Easier to write = a generic shell function.

HTMLify_csv()
{
=C2=A0 =C2=A0 local -rn pFormats=3D"$1"=C2=A0 =C2=A0 local line
=C2=A0 =C2=A0 local -a lFields
=C2=A0 =C2= =A0 printf '<table border=3D1><font size=3D"2">\n= '
=C2=A0 =C2=A0 read -r line
=C2=A0 =C2=A0 IFS=3D'|' read= -r -a lFields <<< "${line}"
=C2=A0 =C2=A0 local -i l= FldCnt=3D${#lFields[@]}
=C2=A0 =C2=A0 printf '<tr>'
=C2= =A0 =C2=A0 for ((i=3D0; i<$lFldCnt; i++)); do printf '<th align= =3D"%s">%s</th>' center "${lFields[i]}"; d= one
=C2=A0 =C2=A0 printf "</tr>\n"
=C2=A0 =C2=A0 whil= e IFS=3D read -r line
=C2=A0 =C2=A0 do
=C2=A0 =C2=A0 =C2=A0 =C2=A0 [[= $line =3D~ rows?\)$ ]] && { printf '<tr><td>%s<= /td></tr>\n' "$line"; continue; }
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 IFS=3D'|' read -r -a lFields <<< "${lin= e}"
=C2=A0 =C2=A0 =C2=A0 =C2=A0 printf '<tr>'
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 for ((i=3D0; i<$lFldCnt; i++))
=C2=A0 =C2=A0= =C2=A0 =C2=A0 do
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 printf '= <td align=3D"%s">%s</td>' "${pFormats[i]}&qu= ot; "${lFields[i]}"
=C2=A0 =C2=A0 =C2=A0 =C2=A0 done
=C2=A0= =C2=A0 =C2=A0 =C2=A0 printf "</tr>\n"
=C2=A0 =C2=A0 don= e
=C2=A0 =C2=A0 printf '</table>\n'
}
=
dec= lare -a Formats=3D(right left)
ps= ql -XAc "select to_char(oid::integer, '99,999') as oid, datnam= e from pg_database;" | HTMLify_csv Formats

=
It requires an array that describes how you want each column aligned.<= /div>

-- =
Death to &l= t;Redacted>, and butter sauce.
Don't boil me, I'm still aliv= e.
<Redacted> lobster!
--000000000000fa1ee5063d663801--