0

I've requested a table dump from our ops division and received something like this (psql's ASCII output):

           session_key            |          expire_date          
----------------------------------+-------------------------------
 hj37s34265p700mvcaspvi26uy44bdtk | 2013-07-15 04:36:34.976036+02
 nsoz2mpv4k08p3dlksdp6sbbfxe7wlp5 | 2013-07-15 04:36:35.881375+02
 2m756uty41c8se0x38phg0j7igxys2ey | 2013-07-15 04:36:45.016556+02
 m6aymeoh5cww1okwgi6fdnpaj6pkgmgv | 2013-07-15 04:36:45.925033+02
 i9k6fk109oq30l2r9mddvns5xttpc4t9 | 2013-07-15 04:36:55.061302+02
 n5cnsapikja5fyp0e1ft1egzmxkmd2o0 | 2013-07-15 04:36:55.96498+02
 nm3crm9okoe2ghz5jnnyxdml8v75vm5p | 2013-07-15 04:37:05.108491+02
 xfomkqrjuf09ffw2rk8uyc6nc93bo2qc | 2013-07-15 04:37:06.001869+02
 tz12zlg3sode7r2jsfy1b7mye0887bgk | 2013-07-15 04:37:15.133397+02
 3jxqsmhig3ee8eeqhw6xogwouz8b3ttx | 2013-07-15 04:37:16.048274+02
(10 rows)

I've starting parsing this with sed, grep, etc., but wondered: is there a way to convert this somewhat regular output to something easier to analyse like CSV?

EDIT: I do not have any access to the actual database in question, all I have is the ASCII output as text file, which I'd like to convert to CSV with PostgreSQL's own means (e.g. on a separate test database).

Nikolai Prokoschenko
  • 7,353
  • 6
  • 48
  • 89
  • 2
    Check out the psql `\copy` command which generates client side CSV files, or the SQL `copy` command (note the missing backslash) which generates server side CSV files (or any other [SQL tool](https://wiki.postgresql.org/wiki/Community_Guide_to_PostgreSQL_GUI_Tools) that can export to CSV) – a_horse_with_no_name Jul 18 '14 at 08:29
  • 1
    @a_horse_with_no_name: I don't have any access to the database, otherwise it'd be very easy ;-) – Nikolai Prokoschenko Jul 18 '14 at 08:56
  • You will need to use tools like sed or awk to turn that into a usable format (or if it's just a single table, use search & replace in your favorite editor) – a_horse_with_no_name Jul 18 '14 at 08:59

0 Answers0