CREATE or REPLACE VIEW vo_mars.epn_core AS SELECT 
text 'granule' AS resource_type,  
text 'profile' AS dataproduct_type, 
name AS target_name, 
text 'planet' AS target_class, 
cast(to_char(date::date,'J') as double precision) AS time_min,
cast(to_char(date::date,'J') as double precision) AS time_max,
NULL AS time_sampling_step_min,
NULL AS time_sampling_step_max,
NULL AS time_exp_min,
NULL AS time_exp_max,
NULL AS spectral_range_min,
NULL AS spectral_range_max,
NULL AS spectral_sampling_step_min,
NULL AS spectral_sampling_step_max,
NULL AS spectral_resolution_min,
NULL AS spectral_resolution_max,
ls_inf AS c1min,
ls_sup AS c1max,
latitude_inf AS c2min,
latitude_sup AS c2max,
NULL as c3min,
NULL as c3max,
NULL as c1_resol_min,
NULL as c1_resol_max,
NULL as c2_resol_min,
NULL as c2_resol_max,
NULL as c3_resol_min,
NULL as c3_resol_max,
text 'body' AS spatial_frame_type,
NULL as incidence_min,
NULL as incidence_max,
NULL as emergence_min,
NULL as emergence_max,
NULL as phase_min,
NULL as phase_max,
text 'phobos' AS instrument_host_name,
text 'august' AS instrument_name, 
text 'pos.longitude pos.latitude' AS measurement_type,
filename AS access_url,
text 'VOTable' AS access_format,
integer '1' AS access_estsize,
integer '5' AS processing_level,
text 'vo paris data centre on behalf of IPSL' AS publisher,
text 'http://cdsads.u-strasbg.fr/abs/1989Natur.341..600B' AS reference,
text 'aerosols profil on mars from august' AS title,
NULL AS collection_id,
text 'atmosphere' AS target_region,
text  'UTC' AS time_scale
FROM vo_mars.aerosols
UNION ALL
SELECT 
text 'dataset' AS resource_type,  
text 'profile' AS dataproduct_type, 
cast(varchar(32) 'mars' as text) AS target_name, 
text 'planet' AS target_class, 
min(cast(to_char(date::date,'J') as double precision)) AS time_min,
max(cast(to_char(date::date,'J') as double precision)) AS time_max,
NULL AS time_sampling_step_min,
NULL AS time_sampling_step_max,
NULL AS time_exp_min,
NULL AS time_exp_max,
NULL AS spectral_range_min,
NULL AS spectral_range_max,
NULL AS spectral_sampling_step_min,
NULL AS spectral_sampling_step_max,
NULL AS spectral_resolution_min,
NULL AS spectral_resolution_max,
min(ls_inf) AS c1min,
max(ls_sup) AS c1max,
min(latitude_inf) AS c2min,
max(latitude_sup) AS c2max,
NULL as c3min,
NULL as c3max,
NULL as c1_resol_min,
NULL as c1_resol_max,
NULL as c2_resol_min,
NULL as c2_resol_max,
NULL as c3_resol_min,
NULL as c3_resol_max,
text 'body' AS spatial_frame_type,
NULL as incidence_min,
NULL as incidence_max,
NULL as emergence_min,
NULL as emergence_max,
NULL as phase_min,
NULL as phase_max,
text 'phobos' AS instrument_host_name,
text 'august' AS instrument_name, 
NULL AS measurement_type,
NULL as access_url,
text 'VOTable' AS access_format,
NULL AS access_estsize,
integer '5' AS processing_level,
text 'vo paris data centre on behalf of IPSL' AS publisher,
text 'http://cdsads.u-strasbg.fr/abs/1989Natur.341..600B' AS reference,
text 'aerosol profil on mars from august' AS title,
NULL AS collection_id,
text 'atmosphere' AS target_region,
text  'UTC' AS time_scale 
FROM vo_mars.aerosols
UNION ALL
SELECT 
text 'granule' AS resource_type,  
text 'profile' AS dataproduct_type, 
name AS target_name, 
text 'planet' AS target_class, 
NULL AS time_min,
NULL AS time_max,
NULL AS time_sampling_step_min,
NULL AS time_sampling_step_max,
NULL AS time_exp_min,
NULL AS time_exp_max,
NULL AS spectral_range_min,
NULL AS spectral_range_max,
NULL AS spectral_sampling_step_min,
NULL AS spectral_sampling_step_max,
NULL AS spectral_resolution_min,
NULL AS spectral_resolution_max,
ls_inf AS c1min,
ls_sup AS c1max,
latitude_inf AS c2min,
latitude_sup AS c2max,
NULL as c3min,
NULL as c3max,
NULL as c1_resol_min,
NULL as c1_resol_max,
NULL as c2_resol_min,
NULL as c2_resol_max,
NULL as c3_resol_min,
NULL as c3_resol_max,
text 'body' AS spatial_frame_type,
NULL as incidence_min,
NULL as incidence_max,
NULL as emergence_min,
NULL as emergence_max,
NULL as phase_min,
NULL as phase_max,
text 'phobos' AS instrument_host_name,
text 'august' AS instrument_name, 
NULL AS measurement_type,
filename AS access_url,
text 'VOTable' AS access_format,
integer '1' AS access_estsize,
integer '5' AS processing_level,
text 'vo paris data centre on behalf of IPSL' AS publisher,
text 'http://cdsads.u-strasbg.fr/abs/1989Natur.341..600B' AS reference,
text 'ozones profil on mars from august' AS title,
text 'no information' AS collection_id,
text 'atmosphere' AS target_region,
text  'UTC' AS time_scale
FROM vo_mars.ozone
UNION ALL
SELECT 
text 'dataset' AS resource_type,  
text 'profile' AS dataproduct_type, 
cast(varchar(32) 'mars' as text) AS target_name,
text 'planet' AS target_class, 
NULL AS time_min,
NULL AS time_max,
NULL AS time_sampling_step_min,
NULL AS time_sampling_step_max,
NULL AS time_exp_min,
NULL AS time_exp_max,
NULL AS spectral_range_min,
NULL AS spectral_range_max,
NULL AS spectral_sampling_step_min,
NULL AS spectral_sampling_step_max,
NULL AS spectral_resolution_min,
NULL AS spectral_resolution_max,
min(ls_inf) AS c1min,
max(ls_sup) AS c1max,
min(latitude_inf) AS c2min,
max(latitude_sup) AS c2max,
NULL as c3min,
NULL as c3max,
NULL as c1_resol_min,
NULL as c1_resol_max,
NULL as c2_resol_min,
NULL as c2_resol_max,
NULL as c3_resol_min,
NULL as c3_resol_max,
text 'body' AS spatial_frame_type,
NULL as incidence_min,
NULL as incidence_max,
NULL as emergence_min,
NULL as emergence_max,
NULL as phase_min,
NULL as phase_max,
text 'phobos' AS instrument_host_name,
text 'august' AS instrument_name, 
text 'pos.longitude pos.latitude' AS measurement_type,
NULL AS access_url,
text 'VOTable' AS access_format,
NULL AS access_estsize,
integer '5' AS processing_level,
text 'vo paris data centre on behalf of IPSL' AS publisher,
text 'http://cdsads.u-strasbg.fr/abs/1989Natur.341..600B' AS reference,
text 'ozones profil on mars from august' AS title,
text 'no information' AS collection_id,
text 'atmosphere' AS target_region,
text  'UTC' AS time_scale
FROM vo_mars.ozone
;
