<html><head></head><body><div class="ydpf357d0a0yahoo-style-wrap" style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:16px;"><div></div>
        <div dir="ltr" data-setdir="false">Dear Markus</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">Thanks for your answer. I thought about v.db.dropcolumn earlier. However, I am trying to include this within a function, following a workflow in which the input vector might have columns with different names, in which case it would be good to be able to select the ones to keep instead of the ones to remove.</div><div dir="ltr" data-setdir="false">For instance, let's say I want to be able to provide either of the following input vectors:</div><div dir="ltr" data-setdir="false">- "vector1", with columns "a, b, c, d, e"</div><div dir="ltr" data-setdir="false">- "vector2", with columns "j, a, k, f, e"</div><div dir="ltr" data-setdir="false">Let's say I want to keep only "a" and "e".</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">If I use v.db.dropcolumn, I'll have to first list the names of all columns (maybe with v.db.select), then match all the column names that I do not want to keep ("b, c, d" in the first case, "j, k, f" in the second), then drop them with v.db.dropcolumn. I thought just selecting which ones I want to keep would be simpler and more straightforward, if there is a tool for that.</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">So far I am doing a long step (I am creating a temporary vector to avoid changing the input):</div><div dir="ltr" data-setdir="false">1) v.extract -t input=<span><span style="color: rgb(0, 0, 0); font-family: Helvetica Neue, Helvetica, Arial, sans-serif; font-size: 16px;">vector1 </span></span>output=temp_vector (here I select only the features, not attribute table)</div><div dir="ltr" data-setdir="false">2) v.db.addtable map=temp_vector columns=a,e (here I do not bother with the names of the undesirable columns)</div><div dir="ltr" data-setdir="false">3) v.db.update map=temp_vector column=e value=1 (here I set a value but I could take it from the original vector1)</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">Following what you suggest, I could do:</div><div dir="ltr" data-setdir="false">1) g.copy vector=vector1,temp_vector</div><div dir="ltr" data-setdir="false">2) (find out a way to list the undesirable column names)</div><div dir="ltr" data-setdir="false">3) v.db.dropcolumn columns=list_undesidable_columns</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">Neither of the solutions is so straightforward, that's why I thought there should be (or could be) another way.</div><div dir="ltr" data-setdir="false">In R, for instance, I can easily subset columns of an sf object using dplyr::select(vector1, a, e). I guess in PostGIS it is also possible to do that with "SELECT statements", even though I am less skilled there. It would be great to have a module in GRASS to do it as well...<br><div><div><br></div></div><div dir="ltr" data-setdir="false">Best</div><div dir="ltr" data-setdir="false">Bernardo</div> </div>
        
        </div><div id="yahoo_quoted_5105890551" class="yahoo_quoted">
            <div style="font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;color:#26282a;">
                
                <div>
                    Em quarta-feira, 9 de fevereiro de 2022 09:28:06 GMT+1, Markus Neteler <neteler@osgeo.org> escreveu:
                </div>
                <div><br></div>
                <div><br></div>
                <div><div dir="ltr">Hi Bernardo,<br clear="none"><br clear="none">On Wed, Feb 9, 2022 at 1:39 AM Bernardo Santos via grass-user<br clear="none"><<a shape="rect" ymailto="mailto:grass-user@lists.osgeo.org" href="mailto:grass-user@lists.osgeo.org">grass-user@lists.osgeo.org</a>> wrote:<br clear="none">><br clear="none">> Dear list,<br clear="none">><br clear="none">> Is there a GRASS GIS command (maybe a v.db.* one) to subset, in a single command, the columns of a vector?<br clear="none">><br clear="none">> What I have: vector "vect" with 5 columns "a, b, c, d, e" in the attribute table<br clear="none">> What I want: vector "vect_sub" with only, for instance, "a, c, e"<br clear="none">><br clear="none">> I can use v.extract to subsample rows, but not columns. What is the easiest way of doing that, what needing many commands (like creating or copying the vector to a new one, creating a new attribute table, then copying only the columns I want).<br clear="none"><br clear="none">Isn't this simply<br clear="none"><br clear="none"><a shape="rect" href="https://grass.osgeo.org/grass80/manuals/vector.html" target="_blank">https://grass.osgeo.org/grass80/manuals/vector.html</a><br clear="none">--> v.db.dropcolumn - Drops a column from the attribute table<br clear="none">connected to a given vector map.<br clear="none">    --> It offers single and multiple column dropping: columns=name[,name,...]<div class="yqt6592161463" id="yqtfd20823"><br clear="none"><br clear="none">> I looked for that in the documentation but did not found it so easily.</div><br clear="none"><br clear="none">Please suggest where to improve the documentation.<br clear="none"><br clear="none">Markus<div class="yqt6592161463" id="yqtfd43421"><br clear="none"></div></div></div>
            </div>
        </div></body></html>