<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="fetching-spatial-data">
      </a>
      13.4.8 Fetching Spatial Data
     </h3>
    </div>
   </div>
  </div>
  <p>
   Geometry values stored in a table can be fetched in internal
        format. You can also convert them to WKT or WKB format.
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      Fetching spatial data in internal format:
     </p>
     <p>
      Fetching geometry values using internal format can be useful
            in table-to-table transfers:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa34993663"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> geom2 <span class="token punctuation">(</span>g <span class="token keyword">GEOMETRY</span><span class="token punctuation">)</span> <span class="token keyword">SELECT</span> g <span class="token keyword">FROM</span> geom<span class="token punctuation">;</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <p>
      Fetching spatial data in WKT format:
     </p>
     <p>
      The
      <a class="link" href="gis-format-conversion-functions.html#function_st-astext">
       <code class="literal">
        ST_AsText()
       </code>
      </a>
      function
            converts a geometry from internal format to a WKT string.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa49038250"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">SELECT</span> <span class="token function">ST_AsText</span><span class="token punctuation">(</span>g<span class="token punctuation">)</span> <span class="token keyword">FROM</span> geom<span class="token punctuation">;</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <p>
      Fetching spatial data in WKB format:
     </p>
     <p>
      The
      <a class="link" href="gis-format-conversion-functions.html#function_st-asbinary">
       <code class="literal">
        ST_AsBinary()
       </code>
      </a>
      function
            converts a geometry from internal format to a
      <a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
       <code class="literal">
        BLOB
       </code>
      </a>
      containing the WKB
            value.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa39383153"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">SELECT</span> <span class="token function">ST_AsBinary</span><span class="token punctuation">(</span>g<span class="token punctuation">)</span> <span class="token keyword">FROM</span> geom<span class="token punctuation">;</span></code></pre>
     </div>
    </li>
   </ul>
  </div>
 </div>
 <br/>
</div>
