Table structure and pgSphere output format

CREATE TABLE chartest (
    id serial,
    objname varchar,
    metadata xml
);

SELECT SET_SPHERE_OUTPUT('HMS');
SELECT SET_SPHERE_OUTPUT_PRECISION(2);

1a. Find all datasets where spectral resolution is better than 80 km/s (using XPath-level constraints)

SELECT id,objname FROM chartest WHERE 
    xpath_array(metadata,
        '//characterizationAxis[axisFrame/ucd=''em'' and resolution/resolutionRefVal/ReferenceValue < 80.0]'
        ) IS NOT NULL;

Results:

 id | objname 
----+---------
  1 | IC3653
  3 | IC3509
(2 rows)

1b. Find all datasets where spectral resolution is better than 80 km/s (using SQL WHERE clause)

SELECT id,objname FROM chartest WHERE
    xpath_number(metadata,
        '//characterizationAxis[axisFrame/ucd=''em'']/resolution/resolutionRefVal/ReferenceValue'
        ) < 80.0;

Results:

 id | objname 
----+---------
  1 | IC3653
  3 | IC3509
(2 rows)

2. Select equatorial coordinates as pgSphere spoint

SELECT id,objname,spoint(
      pi()*xpath_number(metadata,
        '//characterizationAxis[axisFrame/ucd=''pos'']/coverage/location/coord/Position2D/Value2/C1/text()'
      )/180.0,
      pi()*xpath_number(metadata,
        '//characterizationAxis[axisFrame/ucd=''pos'']/coverage/location/coord/Position2D/Value2/C2/text()'
      )/180.0) 
    FROM 
        chartest;

Results:

 id | objname |               spoint                
----+---------+-------------------------------------
  1 | IC3653  | (12h 41m 29.711s , +11d 22m 01.00s)
  2 | IC3468  | (12h 32m 14.202s , +10d 15m 05.51s)
  3 | IC3509  | (12h 34m 11.503s , +12d 02m 59.39s)
(3 rows)

3. Cone search using pgSphere

SELECT id,objname 
    FROM 
        chartest 
    WHERE 
        spoint(
          pi()*xpath_number(metadata,
            '//characterizationAxis[axisFrame/ucd=''pos'']/coverage/location/coord/Position2D/Value2/C1/text()'
          )/180.0,
          pi()*xpath_number(metadata,
            '//characterizationAxis[axisFrame/ucd=''pos'']/coverage/location/coord/Position2D/Value2/C2/text()'
            )/180.0) @ '<(188.5d,11.1d),1.0d>'::scircle;

Results:

 id | objname 
----+---------
  2 | IC3468
  3 | IC3509
(2 rows)

4. Query on the "time" axis

select id,objname 
    FROM 
        chartest 
    WHERE 
        ((xpath_array(metadata,
            '//characterizationAxis[axisFrame/ucd=''time'']/coverage/location/coord/text()'
         ))[1])::varchar::timestamp > '2005-01-01T00:00:00'::timestamp;

Results:

 id | objname 
----+---------
  3 | IC3509
(1 row)