Chris Travers has an interesting series going on about the Object-Oriented and Polymorphic like features that PostgreSQL has built-in. It reminded me of this syntax I have rarely seen used with PostGIS, that is perfectly valid and may be more familiar looking to Oracle and SQL Server spatial folks. It looks something like this, though sadly will only work on unary functions.
SELECT ('LINESTRING(1 2, 3 4)'::geometry).ST_Length;
More common though, if you were to have a table of say geography objects:
CREATE TABLE pois(gid serial primary key, geog geography(LINESTRING,4326)); INSERT INTO pois(geog) VALUES ('LINESTRING(-164.2559 54.0558,-162.0943 54.33243)'::geography) , ('LINESTRING(-46.2559 54.0558,-46.0943 54.33243, -47.1005 55.33243)'::geography); SELECT (geog).ST_Length As len, (geog::geometry).ST_NPoints As n_pt FROM pois;
If you notice though, no keystrokes were saved. We've simply changed the order of the parenthesis. Damn those ().