Sophie

Sophie

distrib > Fedora > 13 > i386 > media > updates > by-pkgid > cb664fc35171072d04824accda2566aa > files > 265

pgadmin3-1.12.2-2.fc13.i686.rpm

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<link rel="STYLESHEET" type="text/css" href="pgadmin3.css">
<title>Query Tool</title>
</head>

<body>

<h3>Query Tool</h3>

<center><img src="images/query.png"></center>

<p>The Query Tool enables you to execute arbitrary SQL commands.</p>

<p>The upper part of the Query Tool contains the SQL Editor
where you type your commands. You may read the query from a file, or
write it out to a file. When writing a file, the encoding of the file
is determined by the file suffix: if it is *.sql, a 8 bit local
character set is used. If *.usql is selected, the file will be
written in UTF-8, which enables the storage of virtually all
characters used throughout the world, according to the coding rules
of the <a href="http://www.unicode.org/">Unicode Consortium</a>. If
you select *.*, the setting from the <a href="options-tab2.html">read/write
unicode option</a> is used.</p>

<p>The edit entry window also contains autocompletion code to help you
write queries. To use autocomplete, simply start typing your query
and then press Control+Space to see a list of possible object names to
insert. For example, type "<i>SELECT * FROM</i> " (without the quotes, but
with the trailing space), and then hit Control and Space together to see
a popup menu of autocomplete options. The autocomplete system is based on
code from <i>psql</i>, the PostgreSQL command line interpreter and will
generally be able to offer autocomplete options in the same places that
it can in <i>psql</i>. You can optionally enable the Tab key to activate
the autocomplete feature as well - the can be done on the
<a href="options-tab3.html">options dialog</a>.</p>

<p>The editor also offers a number of features for helping with code formatting:</p>

<ul>
  <li>The auto-indent feature will automatically indent text to the same depth as the
      previous line when you press return.</li>
  <li>Block indent text by selecting two or more lines and pressing the Tab key.</li>
  <li>Block outdent text that has been indented using the current tab settings using Shift+Tab.</li>
  <li>Comment out SQL by selecting some text and pressing the Control+K.</li>
  <li>Uncomment SQL by selecting some text starting with a comment and pressing Control+Shift+K.</li>
  <li>Shift the selected text to upper case by pressing Control+Shift+U.</li>
  <li>Shift the selected text to lower case by pressing Control+U.</li>
</ul>

<p>If you prefer to build your queries graphically, you can use the
<a href="gqb.html">Graphical Query Builder</a> to generate the SQL
for you.</p>

<p>To execute a query, select Execute from the Query menu,
press the execute toolbar button, or press the F5 function
key. The complete contents of the window
will be sent to the database server, which executes it. You may also
execute just a part of the text, by selecting only the text that you
want the server to execute.</p>

<p>Explain from the Query menu, or F7 function key will execute the
EXPLAIN command. The database server will analyze the query that's
sent to it, and will return the results.
</p><p>
<center><img src="images/query-analyze.png"></center>
</p><p>
The result is displayed as text in the Data Output page, and graphically 
visualized on the Explain page. This enables you to find out how the 
query is parsed, optimized and executed. You can modify the
degree of inspection by changing the Explain options for this in the
Query menu. Please note that "EXPLAIN VERBOSE" can not be displayed graphically.</p>
<p>In case the query you sent to the server using the Execute or
Explain command takes longer than you expect, and you would like to
abort the execution, you can select Cancel from the Query menu, press
the Cancel toolbar button or use Alt-Break function key to abort the
execution.</p>
<p>You can run pgScript scripts by selecting Execute pgScript from the Query menu instead of Execute, or
you press the Execute pgScript toolbar button, or you press the F6 function
key. The complete contents of the edit entry window
will be sent to the pgScript engine, which interprets it. pgScript scripts are 
composed of regular SQL commands but add some enhancements:</p>
<ul>
	<li>Control-of-flow language (<span class="fixed">IF</span> and <span class="fixed">WHILE</span> structures) </li>
	<li>Local variables (<span class="fixed">SET @VARIABLE = 5</span>) </li>
	<li>Random data generators (<span class="fixed">INTEGER(10, 20)</span> or <span class="fixed">REFERENCE(table, column)</span>) </li>
</ul>
<p>For more information on the pgScript language, please look at the 
<a href="pgscript.html">pgScript scripting language reference</a>.</p>
<p>If you want to have help about a SQL command you want to execute,
you can mark a SQL keyword and select SQL Help from the Help menu,
the SQL Help toolbar button or simply press the F1 key. pgAdmin III
will try to locate the appropriate information in the PostgreSQL
documentation for you.</p>
<p>The result of the database server execution will be displayed in
the lower part of the Query Tool. If the last command in the chain of
SQL command sent to the server was as command returning a result set,
this will be shown on the Data Output page. All rowsets from previous
commands will be discarded.</p>
<p>To save the data in the Data Output page to a file, you can use
the <a href="export.html">Export</a> dialog. 
</p>
<p>Information about all commands just executed will go to the
Messages page. The History page will remember all commands executed
and the results from this, until you use Clear History from the Query
menu to clear the window. If you want to retain the history for later
inspection, you can save the contents of the History page to a file
using the Save history option from the Query menu.</p>
<p>The status line will show how long the last query took to
complete. If a dataset was returned, not only the elapsed time for
server execution is displayed, but also the time to retrieve the data
from the server to the Data Output page.</p>
<p>
In the toolbar combobox you can quickly change your database connection from
one database to another, without launching another instance of the query tool. 
Initially, only one database will be available, but by selecting &lt;new connection&gt; from 
the combobox, you can add another connection to it.
</p><p>
<center><img src="images/query-connect.png"></center>
</p>
<p>In the <a href="options-tab3.html">options dialog</a>, you
can specify a default limit for the rowset size to retrieve. By
default, this value will be 100. If the number of rows to retrieve
from the server exceeds this value, a message box will appear asking
what to do to prevent retrieval of an unexpected high amount of data.
You may decide to retrieve just the first rows, as configured with
the max rows setting, or retrieving the complete rowset regardless of
the setting, or abort the query, effectively retrieving zero rows.</p>

<p>If you have queries that you execute often, you can add these to the
favourites menu, and have them automatically put in the buffer when you
select them from the menu. The Manage Favoutites menu option may be used 
to organise your favourites. Alternatively, you can store them as 
<a href="macros.html">Macros</a></p>

<p>The Query Tool also includes a powerful Find and Replace tool. In addition
to offering the normal options found in most tools, a Regular Expression search
mode is included which allows you to perform extremely powerful search
(and replace) operations. Unless your copy of pgAdmin was built against a 
non-standard build of wxWidgets, a built in version of Henry Spencer's regular
expression library is used based on the 1003.2 spec and some (not quite all) of the 
Perl5 extensions.</p>

<p>For more details of the regular expression syntax offered, please see the 
<a href="http://www.wxwindows.org/manuals/2.6.3/wx_wxresyn.html#wxresyn">wxWidgets
documentation</a>.</p>

</body>
</html>