Re: Query output into a space delimited/location sensitive file - Mailing list pgsql-general

From Greg Smith
Subject Re: Query output into a space delimited/location sensitive file
Date
Msg-id Pine.GSO.4.64.0802160048110.21338@westnet.com
Whole thread Raw
In response to Query output into a space delimited/location sensitive file  (Ubence Quevedo <r0d3nt@pacbell.net>)
List 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 by date:

Previous
From: Tom Lane
Date:
Subject: Re: Strict-typing benefits/costs
Next
From: Stefan Niantschur
Date:
Subject: How to return a large String with C