Note that there are some explanatory texts on larger screens.

plurals
  1. POtransform the content of relational table to the specified form using SQL
    primarykey
    data
    text
    <p>I have a database which contains the following columns:</p> <pre><code>key arg1 arg2 arg3 timebegin timeend #1 a b c 1942-06-18 05:30:00+05:30 1945-06-18 05:30:00+05:30 #2 d e f 1940-10-09 05:53:20+05:53:20 1948-10-09 05:53:20+05:53:20 #3 w x y </code></pre> <p>The type of key, arg1, arg2, arg3 is character varying (255) and type of timebegin and timeend is timestamp with time zone.</p> <p>Now I want to transform the relational table to the format given below:</p> <pre><code>&lt;1&gt; &lt;a&gt; &lt;b&gt; &lt;c&gt; //key,arg1,arg2,agr3 &lt;2&gt; &lt;d&gt; &lt;e&gt; &lt;f&gt; &lt;3&gt; &lt;w&gt; &lt;x&gt; &lt;y&gt; &lt;1&gt; &lt;a&gt; &lt;b&gt; 1942-06-18 05:30:00+05:30 //With columns containing time attributes just key, arg1, arg2, timebegin are copied. &lt;1&gt; &lt;a&gt; &lt;b&gt; 1945-06-18 05:30:00+05:30 &lt;1&gt; &lt;d&gt; &lt;e&gt; 1940-10-09 05:53:20+05:53:20 &lt;1&gt; &lt;d&gt; &lt;e&gt; 1948-10-09 05:53:20+05:53:20 </code></pre> <p>Is it possible to convert the relational table to the format given above using SQL. I know that one can dump the contents of a relational table into csv format. But is it also possible to transform the content of relational table to the specified form given above. My database is in postgres 9.1</p> <p>**</p> <p>*> EDIT: RULES:</p> <blockquote> <p><strong>1. First from all rows key, arg1, arg2, arg3 are copied and then 2. For all rows containing NOT NULL timebegin and timeend values: key,arg1,arg2,timebegin and key,arg1,arg2,timeend is copied*</strong></p> </blockquote> <p>**</p> <p>Note: It does not matter to me whether "&lt;>" are placed or not. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload