Re: Formatting Function..

Поиск
Список
Период
Сортировка
От Rolf Østvik
Тема Re: Formatting Function..
Дата
Msg-id Xns951D6DABF5B03rolfostvikjobbyahoon@200.46.204.72
обсуждение исходный текст
Ответ на Formatting Function..  (Vinay Jain <vinayjain@gmail.com>)
Список pgsql-general
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

В списке pgsql-general по дате отправления:

Предыдущее
От: Kazuya Togashi
Дата:
Сообщение: Difference in text/char data matching between 7.3.4 & 7.4.2
Следующее
От: "B.W.H. van Beest"
Дата:
Сообщение: How to filter on timestamps?