[GRASS-user] Manage Sqlite Database columns

Moritz Lennert mlennert at club.worldonline.be
Fri Feb 3 12:31:36 EST 2012


On 03/02/12 17:30, Micha Silver wrote:
>   On 02/03/2012 01:57 PM, Johannes Radinger wrote:
>>
>> 2) Is it possible to change the order of the columns in the attribute table?
>
> In sqlite you can't change the order of the columns, so you'll need to
> create a new table ordered the way you want, then juggle the table names
> so that the grass vector "sees" the new reordered table.
> Suppose, after the first question above you have a vector with columns:
>      cat double, label text, value double, cat2 integer
> and you want the reordered table to be:
>      label, value, cat (the new integer one)
>
> then:
>
> sqlite> CREATE TABLE tmp (label text, value double, cat integer);
> sqlite> INSERT INTO tmp (label, value, cat) SELECT label, value, cat2
> FROM <your_vector>;
> sqlite> ALTER TABLE <your_vector> RENAME TO vector_bak;
> sqlite> ALTER TABLE tmp RENAME TO <your_vector>;
>
Note that in relational database systems order of columns (and rows for 
that matter) in tables is considered as arbitrary and without 
importance. It certainly does not matter for any database operations 
(except possibly for INSERT statements but the use of explicit column 
naming is encouraged for that).

If you want to show the content of a table with a specific column order, 
you have to specifically declare the columns in the desired order in the 
SELECT statement.

Moritz



More information about the grass-user mailing list