Monday, March 14, 2016
Vítaný!
According to the access statistics, my blog has now more readers from the Czech Republic than from the U.S.A. which had the lead for the last few years.
Wednesday, March 9, 2016
More fun with a integrarelational DBMS: SoilGrids
While the SoilGrids FDW in my first post on this subject works fine, I now think there is a better, more flexible, and more elegant way to do it.
Since PostgreSQL has JSON built in, why not return the whole response and parse with SQL? This way you can get all the data from SoilGrids without having to return a bazillion columns, the JSON response can be stored for future use, and indexed as well.
And this is how it looks like:
CREATE FOREIGN TABLE public.soilgrids1km
(response jsonb , -- json also works, PostgreSQL does the correct cast for us
latitude real ,
longitude real )
SERVER soilgrids_srv;
select (response->'properties'->'PHIHOX'->'M'->>'sd1')::REAL / 10.0::real from soilgrids1km where latitude = '51.57' and longitude = '5.39'
5.8
And again, that level of extensibility is one of the reasons why I think that PostgreSQL is one awesome DBMS. Integrarelational even...
Since PostgreSQL has JSON built in, why not return the whole response and parse with SQL? This way you can get all the data from SoilGrids without having to return a bazillion columns, the JSON response can be stored for future use, and indexed as well.
And this is how it looks like:
CREATE FOREIGN TABLE public.soilgrids1km
(response jsonb , -- json also works, PostgreSQL does the correct cast for us
latitude real ,
longitude real )
SERVER soilgrids_srv;
select (response->'properties'->'PHIHOX'->'M'->>'sd1')::REAL / 10.0::real from soilgrids1km where latitude = '51.57' and longitude = '5.39'
5.8
And again, that level of extensibility is one of the reasons why I think that PostgreSQL is one awesome DBMS. Integrarelational even...
Labels:
FDW,
integrarelational,
Multicorn,
postgresql,
REST
Subscribe to:
Posts (Atom)