SpatiaLite conteggio righe tabelle database

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

SpatiaLite conteggio righe tabelle database

pigreco
Salve a tutti,

questa query:

SELECT f_table_name,
       eval('select count(*) from ' || f_table_name) AS nro_feature
FROM geometry_columns;

restituisce a video una tabella con nome geo-tabella e relativo numero di
righe, ovvero
se un database ha 5 geo-tabelle restituirà una tabella con 5 righe e due
colonne: la prima colonna con i nomi delle geo-tabelle e la seconda il
numero complessivo di feature.
Questa query utilizza la tabella 'geometry_columns' e quindi non tiene conto
delle semplici tabelle (cioè quelle senza il campo geometry).

Come potrei scrivere una analoga query per conteggiare le righe delle sole
tabelle (quelle senza geometry)??

Ci riesco con questa, ma sembra bruttina:

SELECT tbl_name,
       eval('select count(*) from ' || tbl_name ) AS nro_righe
FROM sqlite_master
where type='table'
and name not like '%geom%'
and name not like '%spatial%'
and name not like '%sql%'
and name not like '%raster%'
and name not like '%SE%'
and name not like '%vector_%'
and sql not like '%geom%';

grazie

-----
https://pigrecoinfinito.wordpress.com/
--
Sent from: http://gfoss-geographic-free-and-open-source-software-italian-mailing.3056002.n2.nabble.com/
_______________________________________________
[hidden email]
http://lists.gfoss.it/cgi-bin/mailman/listinfo/gfoss
Questa e' una lista di discussione pubblica aperta a tutti.
I messaggi di questa lista non hanno relazione diretta con le posizioni dell'Associazione GFOSS.it.
796 iscritti al 28/12/2017
Reply | Threaded
Open this post in threaded view
|

Re: SpatiaLite conteggio righe tabelle database

a.furieri
On Mon, 29 Apr 2019 12:54:05 -0700 (MST), pigreco wrote:

> Salve a tutti,
>
> questa query:
>
> SELECT f_table_name,
>        eval('select count(*) from ' || f_table_name) AS nro_feature
> FROM geometry_columns;
>
> restituisce a video una tabella con nome geo-tabella e relativo
> numero di
> righe, ovvero
> se un database ha 5 geo-tabelle restituirà una tabella con 5 righe e
> due
> colonne: la prima colonna con i nomi delle geo-tabelle e la seconda
> il
> numero complessivo di feature.
> Questa query utilizza la tabella 'geometry_columns' e quindi non
> tiene conto
> delle semplici tabelle (cioè quelle senza il campo geometry).
>
> Come potrei scrivere una analoga query per conteggiare le righe delle
> sole
> tabelle (quelle senza geometry)??
>
> Ci riesco con questa, ma sembra bruttina:
>
> SELECT tbl_name,
>        eval('select count(*) from ' || tbl_name ) AS nro_righe
> FROM sqlite_master
> where type='table'
> and name not like '%geom%'
> and name not like '%spatial%'
> and name not like '%sql%'
> and name not like '%raster%'
> and name not like '%SE%'
> and name not like '%vector_%'
> and sql not like '%geom%';
>

SELECT tbl_name,
        eval('SELECT count(*) FROM "' || tbl_name || '"') AS nro_righe
FROM sqlite_master
WHERE type='table'
AND name NOT IN (SELECT f_table_name FROM geometry_columns)
ORDER BY tbl_name;

ciao Sandro
_______________________________________________
[hidden email]
http://lists.gfoss.it/cgi-bin/mailman/listinfo/gfoss
Questa e' una lista di discussione pubblica aperta a tutti.
I messaggi di questa lista non hanno relazione diretta con le posizioni dell'Associazione GFOSS.it.
796 iscritti al 28/12/2017
Reply | Threaded
Open this post in threaded view
|

Re: SpatiaLite conteggio righe tabelle database

pigreco
a.furieri wrote

>>
>> Ci riesco con questa, ma sembra bruttina:
>>
>> SELECT tbl_name,
>>        eval('select count(*) from ' || tbl_name ) AS nro_righe
>> FROM sqlite_master
>> where type='table'
>> and name not like '%geom%'
>> and name not like '%spatial%'
>> and name not like '%sql%'
>> and name not like '%raster%'
>> and name not like '%SE%'
>> and name not like '%vector_%'
>> and sql not like '%geom%';
>>
>
> SELECT tbl_name,
>         eval('SELECT count(*) FROM "' || tbl_name || '"') AS nro_righe
> FROM sqlite_master
> WHERE type='table'
> AND name NOT IN (SELECT f_table_name FROM geometry_columns)
> ORDER BY tbl_name;
>
> ciao Sandro

Buongiorno e grazie per la risposta,
la query proposta ottiene tutte le tabelle del database tranne quelle con
geometry e quindi prende anche quelle tabelle del database che non ho creato
direttamente io, es: prende le tabelle idx..., SE.... ecc...
il mio intendo era quello di 'acchiappare' solo le tabelle che ho creato e
popolato io.

saluti

-----
https://pigrecoinfinito.wordpress.com/
--
Sent from: http://gfoss-geographic-free-and-open-source-software-italian-mailing.3056002.n2.nabble.com/
_______________________________________________
[hidden email]
http://lists.gfoss.it/cgi-bin/mailman/listinfo/gfoss
Questa e' una lista di discussione pubblica aperta a tutti.
I messaggi di questa lista non hanno relazione diretta con le posizioni dell'Associazione GFOSS.it.
796 iscritti al 28/12/2017
Reply | Threaded
Open this post in threaded view
|

Re: SpatiaLite conteggio righe tabelle database

a.furieri
On Mon, 29 Apr 2019 23:36:01 -0700 (MST), pigreco wrote:

> a.furieri wrote
>>>
>>> Ci riesco con questa, ma sembra bruttina:
>>>
>>> SELECT tbl_name,
>>>        eval('select count(*) from ' || tbl_name ) AS nro_righe
>>> FROM sqlite_master
>>> where type='table'
>>> and name not like '%geom%'
>>> and name not like '%spatial%'
>>> and name not like '%sql%'
>>> and name not like '%raster%'
>>> and name not like '%SE%'
>>> and name not like '%vector_%'
>>> and sql not like '%geom%';
>>>
>>
>> SELECT tbl_name,
>>         eval('SELECT count(*) FROM "' || tbl_name || '"') AS
>> nro_righe
>> FROM sqlite_master
>> WHERE type='table'
>> AND name NOT IN (SELECT f_table_name FROM geometry_columns)
>> ORDER BY tbl_name;
>>
>> ciao Sandro
>
> Buongiorno e grazie per la risposta,
> la query proposta ottiene tutte le tabelle del database tranne quelle
> con
> geometry e quindi prende anche quelle tabelle del database che non ho
> creato
> direttamente io, es: prende le tabelle idx..., SE.... ecc...
> il mio intendo era quello di 'acchiappare' solo le tabelle che ho
> creato e
> popolato io.
>

SELECT tbl_name,
eval('SELECT count(*) FROM "' || tbl_name || '"') AS nro_righe
FROM sqlite_master
WHERE type = 'table' AND sql NOT LIKE 'CREATE VIRTUAL TABLE %'
AND name NOT IN (SELECT f_table_name FROM geometry_columns)
AND name NOT IN (SELECT 'idx_' || f_table_name || '_' ||
f_geometry_column
          FROM geometry_columns WHERE spatial_index_enabled = 1)
AND name NOT IN (SELECT 'idx_' || f_table_name || '_' ||
f_geometry_column || '_node'
          FROM geometry_columns WHERE spatial_index_enabled = 1)
AND name NOT IN (SELECT 'idx_' || f_table_name || '_' ||
f_geometry_column || '_parent'
          FROM geometry_columns WHERE spatial_index_enabled = 1)
AND name NOT IN (SELECT 'idx_' || f_table_name || '_' ||
f_geometry_column || '_rowid'
          FROM geometry_columns WHERE spatial_index_enabled = 1)
AND name NOT IN ('geometry_columns', 'geometry_columns_auth',
'geometry_columns_time')
ORDER BY tbl_name;

Note:
===========================
1. con queste modifiche filtra automaticamente qualsiasi
    SpatialIndex e tutte le VirtualTables
2. l'ultima lista (geometry_columns etc) va espansa fino
    a definire l'elenco completo di tutte le meta-tavole
    utilizzate internamente da SpatiaLite.
    lavoro noiosetto ma per nulla difficoltoso, basta solo
    un pizzico di pazienza.
3. non copre eventuali TopoGeometry, TopoNetworks e
    RasterCoverages, ma non credo che ti interessino.
    nal caso, il problema e' facilmente risolvibile
    ricalcando lo schema applicato agli Spatial Index;
    occorre fare una subquery sulla metatavola madre
    per ricavare tutti i nomi delle tavole figlie.

ciao Sandro
_______________________________________________
[hidden email]
http://lists.gfoss.it/cgi-bin/mailman/listinfo/gfoss
Questa e' una lista di discussione pubblica aperta a tutti.
I messaggi di questa lista non hanno relazione diretta con le posizioni dell'Associazione GFOSS.it.
796 iscritti al 28/12/2017
Reply | Threaded
Open this post in threaded view
|

Re: SpatiaLite conteggio righe tabelle database

pigreco
a.furieri wrote

> SELECT tbl_name,
> eval('SELECT count(*) FROM "' || tbl_name || '"') AS nro_righe
> FROM sqlite_master
> WHERE type = 'table' AND sql NOT LIKE 'CREATE VIRTUAL TABLE %'
> AND name NOT IN (SELECT f_table_name FROM geometry_columns)
> AND name NOT IN (SELECT 'idx_' || f_table_name || '_' ||
> f_geometry_column
>           FROM geometry_columns WHERE spatial_index_enabled = 1)
> AND name NOT IN (SELECT 'idx_' || f_table_name || '_' ||
> f_geometry_column || '_node'
>           FROM geometry_columns WHERE spatial_index_enabled = 1)
> AND name NOT IN (SELECT 'idx_' || f_table_name || '_' ||
> f_geometry_column || '_parent'
>           FROM geometry_columns WHERE spatial_index_enabled = 1)
> AND name NOT IN (SELECT 'idx_' || f_table_name || '_' ||
> f_geometry_column || '_rowid'
>           FROM geometry_columns WHERE spatial_index_enabled = 1)
> AND name NOT IN ('geometry_columns', 'geometry_columns_auth',
> 'geometry_columns_time')
> ORDER BY tbl_name;
>
> Note:
> ===========================
> 1. con queste modifiche filtra automaticamente qualsiasi
>     SpatialIndex e tutte le VirtualTables
> 2. l'ultima lista (geometry_columns etc) va espansa fino
>     a definire l'elenco completo di tutte le meta-tavole
>     utilizzate internamente da SpatiaLite.
>     lavoro noiosetto ma per nulla difficoltoso, basta solo
>     un pizzico di pazienza.
> 3. non copre eventuali TopoGeometry, TopoNetworks e
>     RasterCoverages, ma non credo che ti interessino.
>     nal caso, il problema e' facilmente risolvibile
>     ricalcando lo schema applicato agli Spatial Index;
>     occorre fare una subquery sulla metatavola madre
>     per ricavare tutti i nomi delle tavole figlie.
>
> ciao Sandro

Grazie per lo spunto e il tempo dedicatomi.

saluti

-----
https://pigrecoinfinito.wordpress.com/
--
Sent from: http://gfoss-geographic-free-and-open-source-software-italian-mailing.3056002.n2.nabble.com/
_______________________________________________
[hidden email]
http://lists.gfoss.it/cgi-bin/mailman/listinfo/gfoss
Questa e' una lista di discussione pubblica aperta a tutti.
I messaggi di questa lista non hanno relazione diretta con le posizioni dell'Associazione GFOSS.it.
796 iscritti al 28/12/2017