[GRASS-user] Change the length and type of columns in an attribute table

Hello all,

I have a problem when I want to modify an attribute table.

I add a new vector with v.in.ogr. My attribute table is build like that :

name type length

cat integer 20
ID character 24
PREC_PLANI double precision 20
NATURE character 31
HAUTEUR integer 20
id_2 integer 20

I would like to remove the column ‘HAUTEUR’, but when I remove this
column, my two character columns (ID and NATURE) change automatically to
become :

ID text 1000
NATURE text 1000

Do you know why the simple fact to remove a column (HAUTEUR) change type
and length of other columns.

Thanks,

···

Camille BEZZINA
Chargé d’études géomatiques et photomontages
Geophom
57 rue du Chemin Neuf 44521 OUDON
Standard: +33(0)2 85 52 02 59
Ligne directe: +33(0)9 72 56 81 71
www.geophom.fr

On Wed, Apr 4, 2018 at 5:54 PM, Camille Bezzina <camille.bezzina@geophom.fr> wrote:

Hello all,

I have a problem when I want to modify an attribute table.

I add a new vector with v.in.ogr. My attribute table is build like that :

name type length

cat integer 20
ID character 24
PREC_PLANI double precision 20
NATURE character 31
HAUTEUR integer 20
id_2 integer 20

I would like to remove the column ‘HAUTEUR’, but when I remove this
column, my two character columns (ID and NATURE) change automatically to
become :

ID text 1000
NATURE text 1000

Do you know why the simple fact to remove a column (HAUTEUR) change type
and length of other columns.

The reason is that GRASS uses SQLite as database manager, and in SQLite there is nothing like varchar(24), only text without any length restrictions. That means, when importing vector data with attributes, any text fields are converted to text by SQLite itself. The value 1000 as length for text is somewhat misleading here because the maximum allowed length in SQLite is by default 1 billion.

Markus M

Thanks,

Camille BEZZINA
Chargé d’études géomatiques et photomontages
Geophom
57 rue du Chemin Neuf 44521 OUDON
Standard: +33(0)2 85 52 02 59
Ligne directe: +33(0)9 72 56 81 71
www.geophom.fr


grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

Ok thanks Markus for your answer.

But I have another question :

I have 2 differents vectors with the same attribute table structure.

This problem is just for one of them.

For the first vector the attribute table is like that :

name type length

cat integer 20
ID character 24
PREC_PLANI double precision 20
NATURE character 31
HAUTEUR integer 20
id_2 integer 20

and for the second :

name type length

cat integer 20
ID text 1000
PREC_PLANI double precision 20
NATURE text 1000
HAUTEUR integer 20
id_2 integer 20

So when I want to patch my 2 vectors with v.patch, there is the following message :

(Thu Apr 5 15:01:50 2018)
v.patch -e --overwrite --verbose input=zone_vegetation_D90_decoupe@AIP_RONCHAMP_MNE,zone_vegetation_D70_decoupe@AIP_RONCHAMP_MNE output=TEST_merge_D70_D90
ERROR: Length of string columns differ
(Thu Apr 5 15:01:51 2018) La commande s’est terminée (1 sec)

···

Le 05/04/2018 à 14:41, Markus Metz a écrit :

On Wed, Apr 4, 2018 at 5:54 PM, Camille Bezzina <camille.bezzina@geophom.fr> wrote:

Hello all,

I have a problem when I want to modify an attribute table.

I add a new vector with v.in.ogr. My attribute table is build like that :

name type length

cat integer 20
ID character 24
PREC_PLANI double precision 20
NATURE character 31
HAUTEUR integer 20
id_2 integer 20

I would like to remove the column ‘HAUTEUR’, but when I remove this
column, my two character columns (ID and NATURE) change automatically to
become :

ID text 1000
NATURE text 1000

Do you know why the simple fact to remove a column (HAUTEUR) change type
and length of other columns.

The reason is that GRASS uses SQLite as database manager, and in SQLite there is nothing like varchar(24), only text without any length restrictions. That means, when importing vector data with attributes, any text fields are converted to text by SQLite itself. The value 1000 as length for text is somewhat misleading here because the maximum allowed length in SQLite is by default 1 billion.

Markus M

Thanks,

Camille BEZZINA
Chargé d’études géomatiques et photomontages
Geophom
57 rue du Chemin Neuf 44521 OUDON
Standard: +33(0)2 85 52 02 59
Ligne directe: +33(0)9 72 56 81 71
www.geophom.fr


grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

Camille BEZZINA
Chargé d’études géomatiques et photomontages
Geophom
57 rue du Chemin Neuf 44521 OUDON
Standard: +33(0)2 85 52 02 59
Ligne directe: +33(0)9 72 56 81 71
www.geophom.fr

On Thu, Apr 5, 2018 at 3:30 PM, Camille Bezzina <camille.bezzina@geophom.fr> wrote:

Ok thanks Markus for your answer.

But I have another question :

I have 2 differents vectors with the same attribute table structure.

This problem is just for one of them.

For the first vector the attribute table is like that :

name type length

cat integer 20
ID character 24
PREC_PLANI double precision 20
NATURE character 31
HAUTEUR integer 20
id_2 integer 20

and for the second :

name type length

cat integer 20
ID text 1000
PREC_PLANI double precision 20
NATURE text 1000
HAUTEUR integer 20
id_2 integer 20

So when I want to patch my 2 vectors with v.patch, there is the following message :

(Thu Apr 5 15:01:50 2018)
v.patch -e --overwrite --verbose input=zone_vegetation_D90_decoupe@AIP_RONCHAMP_MNE,zone_vegetation_D70_decoupe@AIP_RONCHAMP_MNE output=TEST_merge_D70_D90
ERROR: Length of string columns differ
(Thu Apr 5 15:01:51 2018) La commande s’est terminée (1 sec)

I see. v.db.dropcolumn was removing the field length for SQLite tables, fixed in trunk r72591.

Markus M

Le 05/04/2018 à 14:41, Markus Metz a écrit :

On Wed, Apr 4, 2018 at 5:54 PM, Camille Bezzina <camille.bezzina@geophom.fr> wrote:

Hello all,

I have a problem when I want to modify an attribute table.

I add a new vector with v.in.ogr. My attribute table is build like that :

name type length

cat integer 20
ID character 24
PREC_PLANI double precision 20
NATURE character 31
HAUTEUR integer 20
id_2 integer 20

I would like to remove the column ‘HAUTEUR’, but when I remove this
column, my two character columns (ID and NATURE) change automatically to
become :

ID text 1000
NATURE text 1000

Do you know why the simple fact to remove a column (HAUTEUR) change type
and length of other columns.

The reason is that GRASS uses SQLite as database manager, and in SQLite there is nothing like varchar(24), only text without any length restrictions. That means, when importing vector data with attributes, any text fields are converted to text by SQLite itself. The value 1000 as length for text is somewhat misleading here because the maximum allowed length in SQLite is by default 1 billion.

Markus M

Thanks,

Camille BEZZINA
Chargé d’études géomatiques et photomontages
Geophom
57 rue du Chemin Neuf 44521 OUDON
Standard: +33(0)2 85 52 02 59
Ligne directe: +33(0)9 72 56 81 71
www.geophom.fr


grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user


Camille BEZZINA
Chargé d’études géomatiques et photomontages
Geophom
57 rue du Chemin Neuf 44521 OUDON
Standard: +33(0)2 85 52 02 59
Ligne directe: +33(0)9 72 56 81 71
www.geophom.fr