Re: Query output into a space delimited/location sensitive file

Поиск
Список
Период
Сортировка
От Greg Smith
Тема Re: Query output into a space delimited/location sensitive file
Дата
Msg-id Pine.GSO.4.64.0802160048110.21338@westnet.com
обсуждение исходный текст
Ответ на Query output into a space delimited/location sensitive file  (Ubence Quevedo <r0d3nt@pacbell.net>)
Список pgsql-general
On Fri, 15 Feb 2008, Ubence Quevedo wrote:

> What would the command be to have a query result be put into a location/space
> sensitive file [position 1 through 5 would be one thing where position 6
> through 10 would be the next field, 11 through 16 another, etc]?  Is this
> even possible with Postgres?

Check out string operators like rpad and maybe even overlay in
http://www.postgresql.org/docs/current/static/functions-string.html , the
date/number formatting operations in
http://www.postgresql.org/docs/current/static/functions-formatting.html ,
and note that you can combine strings with || in between them.

You can do something like this:

select rpad(field1,5) || rpad(field2,5) || rpad(field3,5) from table1

To get back a string formatted the way you describe.  You may have to
tweak that to get the formatting on the fields exactly right.  Will be
kind of brute force and fragile if anything changes, but it should work if
you tinker enough.

--
* Greg Smith gsmith@gregsmith.com http://www.gregsmith.com Baltimore, MD

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Strict-typing benefits/costs
Следующее
От: Stefan Niantschur
Дата:
Сообщение: How to return a large String with C