Just for the hack of it, can I peddle a postgres version of a 'solution'?

Assuming a postgres instance, with module file_fdw installed, and your 5 text lines tab-separated saved under '/tmp/table.txt':

create server abc_server foreign data wrapper file_fdw; create foreign table file_table ( c1 text, i2 int, i3 int) server abc_server options ( filename '/tmp/table.txt', format 'csv', delimiter E'\t' + ); select c1, i2, i3 from file_table order by c1; select c1, i2 from file_table order by i2 desc; select c1, i3 from file_table order by i3 desc; select c1 , rank() over (order by i2 desc) , rank() over (order by i3 desc) from file_table order by c1;

Output (mimicking yours):

$ psql -qXf table.sql c1 | i2 | i3 ----+----+---- a | 23 | 11 b | 24 | 15 c | 16 | 19 d | 8 | 2 e | 40 | 41 (5 rows) c1 | i2 ----+---- e | 40 b | 24 a | 23 c | 16 d | 8 (5 rows) c1 | i3 ----+---- e | 41 c | 19 b | 15 a | 11 d | 2 (5 rows) c1 | rank | rank ----+------+------ a | 3 | 4 b | 2 | 3 c | 4 | 2 d | 5 | 5 e | 1 | 1 (5 rows)

Not entirely serious as a solution but I thought is was cute all the same: it is also the shortest till now, with only 3 lines :)


In reply to Re: manipulating a data table by erix
in thread manipulating a data table by v15

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.