ChernoWiki.ru: web collaboraion (powered by CoWiki)
Current user:   guest    Change     Preferences 
   List directory   History   Similar   Print version 
root 
dev 
   PostgreSQL 
   PHP 
   XML 
   DHTML 
   Design Patterns 
   Graph in RDBMS 
   Social networks 
   Adaptive Web 
   Wiki 
   Philosophy 
os 
   Unix, Linux, FreeBSD 
other 
   Hello 
   searchers 



dev > PostgreSQL > XML type > Examples

 
rw-rw-r--   ns   wheel

Examples

Characterization Data Model

CREATE TABLE chardm (
    id SERIAL,
    data XML
);

-- inserting the data
INSERT INTO chardm (data) VALUES ('
<!-- edited with XMLSpy v2005 rel. 3 U (http://www.altova.com) by bonnarel (CDS) -->
<MPFS xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:stc="http://www.ivoa.net/xml/STC/v1.30"  xmlns:cha="urn:vo-characterization">
<Characterization>
        <characterizationAxis>
                <axisFrame>
                    <axisName>spatial</axisName>
                    <calibrationStatus>CALIBRATED</calibrationStatus>
                    <ucd>pos</ucd>
                    <unit>deg</unit>
                    <coordsystem ID="TT-ICRS-WAVELENGTH-TOPO">
                       TT-ICRS-WAVELENGTH-TOPO
                    </coordsystem>
                   
                    <accuracy>
                      <statError>
                        <flavor>statistical error</flavor>
                        <ErrorRefVal>
                         0.00055 0.00055
                        </ErrorRefVal>
                      </statError>
                    </accuracy>
                    <independantAxis>true</independantAxis>
                    <numBins>16 16</numBins>
                    <undersamplingStatus>false</undersamplingStatus>
                    <regularsamplingStatus>true</regularsamplingStatus>
                </axisFrame>     
                <coverage>
                    <location>
                      <coord> 
                        190.37379       11.366944 
                      </coord>
                      <documentation>
                      </documentation>
                    </location>
                    <bounds>
                      <limits>
                       190.37157     11.364722   190.37601     11.369167 
                      </limits>
                      <documentation>
                      </documentation>
                    </bounds>
                </coverage>
                <resolution>
                    <unit> arcsec </unit>
                    <resolutionRefVal>
                      <ReferenceValue>  1.4          </ReferenceValue>
                    </resolutionRefVal>
                </resolution>
                <samplingPrecision>
                    <unit> arcsec </unit>
                    <samplingPrecisionRefVal>
                          <referenceValue>
                    <samplingPeriod> 1.0 </samplingPeriod>
                           </referenceValue>
                    </samplingPrecisionRefVal>
                </samplingPrecision>
           </characterizationAxis>
           <characterizationAxis>
                <axisFrame>
                    <axisName>time</axisName>
                    <calibrationStatus>UNCALIBRATED</calibrationStatus>
                    <ucd>time</ucd>
                    <unit> s </unit>
                    <coordsystem IDREF="TT-ICRS-WAVELENGTH-TOPO" />
                                
                    
                    
                    <accuracy>
                    </accuracy>
                    <independantAxis>true</independantAxis>
                    <numBins>1</numBins>
                    
                </axisFrame>     
                <coverage>
                    <location>
                      <coord coordsystem_id="">
                        
                         2004/24/05 22:23:58 
                        
                      </coord>
                      
                    </location>
                 
                </coverage>
                
                
           </characterizationAxis>
           <characterizationAxis>
                <axisFrame>
                   <axisName>spectral</axisName>
                   <calibrationStatus>CALIBRATED</calibrationStatus>
                   <ucd>em</ucd>
                   <unit> um </unit>
                   <coordsystem ID="SPEC-SYS">
                                SPEC-SYS
                   </coordsystem>
                  
                   <accuracy>
                     <statError>
                        <flavor>statistical error</flavor>
                        <ErrorRefVal>
                         0.0001
                        </ErrorRefVal>
                      </statError>
                   </accuracy>
                   <independantAxis>true</independantAxis>
                   <numBins>2048</numBins>
                   <undersamplingStatus>false</undersamplingStatus>
                   <regularsamplingStatus>false</regularsamplingStatus>
                </axisFrame>     
                <coverage>
                   <location>
                      <coord>
                        
                          0.4858137 
                        
                      </coord>
                      
                  </location>
                      <bounds>
                        <limits>
                          0.4140   0.56548382 
                        </limits>
                       
                      </bounds>
                </coverage>
                <resolution>
                      <unit> km/s </unit>
                      <resolutionRefVal>
                         <ReferenceValue>78.6162 </ReferenceValue>
                      </resolutionRefVal>
                      <resolutionBounds>
                         <limits>
                            48.3233    
                            101.142    
                         </limits>
                      </resolutionBounds>
                </resolution>
                <samplingPrecision>
                      <unit> km/s </unit>
                      <samplingPrecisionRefVal>
                                <ReferenceValue>
                         <samplingPeriod>40.0000</samplingPeriod>
                                </ReferenceValue>
                      </samplingPrecisionRefVal>
                      
               </samplingPrecision>
           </characterizationAxis>
           <characterizationAxis>
               <axisFrame>
                    <axisName>flux</axisName>
                    <calibrationStatus>UNCALIBRATED</calibrationStatus>
                    <ucd>phot</ucd>
                    <unit> </unit>
                    <coordsystem ID="Pixel">
                                TBD
                    </coordsystem>
                    
                    <accuracy>
                     <statError>
                        <flavor>statistical error</flavor>
                        <ErrorRefVal>
                          5.63e-17
                        </ErrorRefVal>
                        <ErrorBounds>
                         <ErrorLimits>
                           5.80e-19 1.12e-16
                         </ErrorLimits>
                        </ErrorBounds>
                      </statError>
                    </accuracy>
                    <independantAxis>false</independantAxis>
                    
                    <undersamplingStatus>false</undersamplingStatus>
                    <regularsamplingStatus>true</regularsamplingStatus>
               </axisFrame>     

               <coverage>
                    <location>
                       <coord>
                         2.3519587e-17 
                         
                       </coord>
                       
                    </location>
                    <bounds>
                       <limits>
                          -2.8933970e-15  1.1838107e-14
                       </limits>
                       
                    </bounds>
               </coverage>
              
           </characterizationAxis>
</Characterization>
</MPFS>
');

-- creating implicit type casts for future convenient queries
CREATE CAST (XML AS TEXT) WITHOUT FUNCTION AS IMPLICIT;
CREATE CAST (XML AS VARCHAR) WITHOUT FUNCTION AS IMPLICIT;

Simpliest queries:

-- get all <coord> elements as array of xmls
SELECT 
    xpath_array(data, '//coord') 
FROM 
    chardm;
-- get second element in sequence (array) of xmls
SELECT 
    (xpath_array(data, '//coord'))[2] 
FROM 
    chardm;
-- get RA of the observation (which is descendant of <Position2D> element) as a real number
SELECT xpath_number(data, '//coord/Position2D/descendant::C1/text()') FROM chardm WHERE id = 3;



Reference Examples
http://chernowiki.ru/Dev/Examples


Prev. pgxmltype   preTODO Next


Russian Internet News | AJAX news | avianews

Driven by coWiki 0.3.4 (Boron) web collaboration tool. Processed in 0.076 sec.