vinayjain@gmail.com (Vinay Jain) wrote in
news:c729bfe0040704221910989de8@mail.gmail.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