Re: Formatting Function..

From: "Rolf stvik" <rolfostvikjobb(at)yahoo(dot)no>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Formatting Function..
Date: 2004-07-05 08:46:51
Message-ID: Xns951D6DABF5B03rolfostvikjobbyahoon@200.46.204.72
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

vinayjain(at)gmail(dot)com (Vinay Jain) wrote in
news:c729bfe0040704221910989de8(at)mail(dot)gmail(dot)com:

> Hi..
> I am newbe in postgresql so please help me though the question may be
> very easy to answer..
> Is there any formatting function to get output with fix lengths..for
> example my query is..
> schema is:
>
> Student
> (name Varchar,
> age integer);
>
> select name, age from student;
> the output is like this..
> Name | Age
> xyz | 22

I am a little curious about where you want your data to be presented. If it
is only output in psql or other places where text is presented with a fixed
with font then my suggestions will help.
(If the data is to be outputted in html format then there are other
methods.)

One option is to store text data in char coloumns, it will fill the field
with spaces to the left. This i will only recommend in special cases.

Use formatting functions instead
for text use lpad and rpad
for numbers use to_char
example:
select rpad(name,20) as 'Name', to_char(age,'9999') as 'Age' from student;

read more about it in the manual (Chapter 9 in the 7.4. documentation)
--
Rolf

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ramesh Yeligar 2004-07-05 09:40:34 help required
Previous Message Vinay Jain 2004-07-05 08:23:36 Re: Formatting Function..