The definition of SRID 4326 is in fact IN DEGREES. ALso as it says in the ST_DWithin page:
Returns true if the geometries are within the specified distance of one another. For geometry units are in those of spatial reference and For geography units are in meters and measurement is defaulted to use_spheroid=true (measure around spheroid),
Since you're are using the 4326 SRID, you can cast from geometry to geography and vice versa like this :
select st_distance(<geom_column>::geography) from myTable;
Most of the functions in postgis are overloaded, meaning, they return values and run a different procedure based on the input data type.
eg:
boolean ST_DWithin(geometry g1, geometry g2, double precision distance_of_srid);
boolean ST_DWithin(geography gg1, geography gg2, double precision distance_meters);
they have the same name, but the first function returns T/F based on units of the srid, and the second returns T/F based on meters.
If you plug into the function geog types, for its calculation, will take into account the curve of the earth so the algorithm 'costs' a bit more.
If you want to check how much more it costs, you can run for each query an EXPLAIN-ANALYSE
The theory yes, though you could find it very complex indeed.
- Every table (select * from pg_class) has columns.
- Every column (select * from pg_attribute) optionally has a "typmod" number.
- For types with typmod (select * from pg_type) there will be a "typmodout" function.
- Running the typmod out function on a typmod number will return a string that can be concatenated with the type name to form the kind of user-readable signature you're used to (select 'numeric' || numerictypmodout(786441)) (select geography_typmod_out(1107460))
But, hey, psql generates the strings you want, if we look at what SQL it generates, maybe the answer is in there.
Sure enough, there is a magic function that takes a typeid and typmod and returns the magic string.
select a.attname, format_type(a.atttypid, a.atttypmod) from pg_attribute a where attname = 'geog';
With a join to pg_class you should be able to get this info per-table.
Best Answer
Newer versions of PostGIS allow the following, slightly more common, syntax:
Then use ST_SetSrid and ST_MakePoint to populate the column:
See documentation here: