Anybody know why the geoserver does not implement a direct sql query when setup a layer?
+1
A:
The developers just hadn't gotten around to it yet. (There is not a huge need for this feature since GeoServer can serve a database view as easily as a table.)
This feature was implemented recently, and there's currently a mailing list thread about how to expose the configuration option to end users. See http://old.nabble.com/Creating-feature-types-from-SQL-queries:-a-plan-for-GeoServer-to28388933.html
David Winslow
2010-04-30 03:39:43