This is what I want: when I zoom out, cities of the country should appear as points and at a certain level when I zoom in, I want them to appear as polygons (showing the area of the city and boundaries). How can I do that? I am thinking of creating two tables "cities_points" and "cities_polygons" in my PostGIS database. Any idea? (actually not only the cities, but it's the same for other components of my map).
You can take advantage of layer groups in geoserver.
Having in PostGIS the two geometries in separated tables, just create a layer group in geoserver with both layers and by means of SLD styling set the scale under which every layer should be rendered (use maxscaledenominator & minscaledenominator parameters).
One approach would be to create a view of the polygon centroids and manually add it to the geometry_columns table. The benifit of this method is that there is practically no maintenance of the points table as it will show any updates to the polygon table and make use of any of its indexes. The view creation would look something like this:
CREATE VIEW the_schema.city_points AS SELECT id, foo, bar, etc, ST_Centroid(the_geom);
Then add it to the geometry_columns table, like so:
INSERT INTO geometry_columns(f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, "type") SELECT '', 'the_schema', 'city_points', 'the_geom', ST_CoordDim(the_geom), ST_SRID(the_geom), GeometryType(the_geom) FROM the_schema.city_points LIMIT 1;
Hope that helps.
Which technology (apart from PostGIS, obviously) do you use? Is it a web application? If so, I'd recommend using Leaflet.js with a GeoJSON overlay from a server resource which returns either points or polygons depending on the zoom level you query the resource with. I can be more specific if i know the details.