Re: thousands comma numeric formatting in psql

From: Eugen Nedelcu <eugen(at)sifolt(dot)ro>
To: pgsql-patches(at)postgresql(dot)org
Cc: Bruno Wolff III <bruno(at)wolff(dot)to>
Subject: Re: thousands comma numeric formatting in psql
Date: 2005-06-21 13:03:43
Message-ID: 20050621130343.GB367@sifolt.ro
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

On Tue, Jun 21, 2005 at 06:59:38AM -0500, Bruno Wolff III wrote:
> On Tue, Jun 21, 2005 at 08:42:16 +0300,
> Eugen Nedelcu <eugen(at)sifolt(dot)ro> wrote:
> >
> > One solution to deal with this is to use to_char function, but for
> > complex selects against multiple tables it's not a good option.
>
> Why not? You only have to apply it to the output expressions that
> need it.

I think this:

select * from table_with_text_and_numeric_fields;

is much,much easier than:

select text_field1,text_field2,to_char(numeric_field1, '99G999G999'),
to_char(numeric_field2, '9G999G999G999'), text_field3,
text_field4, to_char(numeric_field3, 'MI90G999D99') from
table_with_text_and_numeric_fields;

>
> Note that if you output numbers like this, you also need to be able to
> read them back in. I don't think adding complexity for doing that is
> worth not having to add a few to_char calls in your select queries.
>

I don't know what 'read them back in' means to you.
This formatting is only done when the number is output to the screen.

Something like:
fputs(thousands_comma_number, fout)
instead of:
fputs(original_number, fout)

If you want to output to some file for reading back later, you could
turn the feature off with the backslash switch '\n'.

This is a patch for psql client and not for the backend. It's role
is to output numbers to screen in easy readable form (2,345,675,454,543
is much easier to read then 2345675454543.456). I think graphical
clients like pgAdmin or phppgadmin have a way to do this. I don't know
this for sure but I will investigate it.

Best Regards,
Eugen

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2005-06-21 13:11:07 Re: Escape handling in strings
Previous Message Matthew T. O'Connor 2005-06-21 12:56:58 Re: [PATCHES] default database creation with initdb

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2005-06-21 13:23:39 Re: [PATCHES] O_DIRECT for WAL writes
Previous Message Bruno Wolff III 2005-06-21 11:59:38 Re: thousands comma numeric formatting in psql