My database contains both Spatial and Non-Spatial tables, but I want to retrieve only Spatial table from the query.
Any suggestions to select only Spatial tables. 'the_geom' is the geometry column in the spatial table.
Otherwise, is it possible to select tables from its column name.
I tried with this code select relname from pg_stat_user_tables WHERE schemaname='public'
; but from this we get all table names.
3 Answers 3
All spatial table references are held in the geometry_columns metadata table. So try:
select * from geometry_columns
and you should get just the spatial tables
-
Thank u very much...I think I have missed a simple thingKishor– Kishor2012年08月08日 06:58:56 +00:00Commented Aug 8, 2012 at 6:58
-
2I got another code,
SELECT table_name FROM information_schema.columns WHERE column_name = 'the_geom'
Kishor– Kishor2012年08月08日 07:01:03 +00:00Commented Aug 8, 2012 at 7:01 -
yip- that's the long way around :-)mapoholic– mapoholic2012年08月08日 07:09:20 +00:00Commented Aug 8, 2012 at 7:09
-
-
1@kishor, you should add your comment as an "answer", just so people see it as an option, too, even if its been established that mapoholic's answer may be the preferred method.RyanKDalton– RyanKDalton2012年08月08日 14:19:21 +00:00Commented Aug 8, 2012 at 14:19
Another one to select only spatial tables in database..
SELECT table_name FROM information_schema.columns WHERE column_name = 'the_geom'`
Using this code we can also retrieve table info by knowing its column name.
Short way
select * from geometry_columns
Deeper way
SELECT table_name FROM information_schema.columns WHERE column_name = 'the_geom' or column_name = 'wkb_geometry'
The second option should work even if the information of geometry_columns have been deleted. The 'wkb_geometry' is the default name of geometry data columns if you used ogr2ogr tool to feed your database.