我应该如何在不使用 PostGIS 的情况下在 Postgres 中表示纬度和经度?我使用的系统不允许 SQL passthrough,所以我不能使用 POSTGIS。
您还可以为latitude
和使用单独的列,longitude
或者创建您自己的类型。无论哪种方式,约束允许的值都可能是好的,在这个例子中,如果类型用于多个表,我还使用域来避免重复约束:
create domain latitude_t as double precision not null
check(value>=-90 and value<=90);
create domain longitude_t as double precision not null
check(value>-180 and value<=180);
create type geocoord_t as (latitude latitude_t, longitude longitude_t);
create table my_table(id serial, geocoord geocoord_t);
insert into my_table(geocoord) values ((31.778175,35.22995));
select id, (geocoord).* from my_table;
id | latitude | longitude
----+-----------+-----------
1 | 31.778175 | 35.22995
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7348 次 |
最近记录: |