Debian Codegraph @

doc/html/pgtcl-pgsqlite.html

raw symbols SCIP
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2 "http://www.w3.org/TR/html4/loose.dtd">
3 <html>
4 <head>
5 <meta name="generator" content="HTML Tidy for HTML5 for Linux version 5.6.0">
6 <title>pg_sqlite</title>
7 <meta name="GENERATOR" content="Modular DocBook HTML Stylesheet Version 1.79">
8 <link rev="MADE" href="mailto:[email protected]">
9 <link rel="HOME" title="PostgreSQL Tcl Interface Documentation" href="index.html">
10 <link rel="UP" title="pgtcl Command Reference" href="libpgtcl-ref.html">
11 <link rel="PREVIOUS" title="pg_lo_export" href="pgtcl-pgloexport.html">
12 <link rel="NEXT" title="pg_copy_complete" href="pgtcl-pgcopycomplete.html">
13 <link rel="STYLESHEET" type="text/css" href="stylesheet.css">
14 </head>
15 <body class="REFENTRY">
16 <div class="NAVHEADER">
17 <table summary="Header navigation table" width="100%" border="0" cellpadding="0" cellspacing="0">
18 <tr>
19 <th colspan="5" align="center" valign="bottom">PostgreSQL Tcl Interface Documentation</th>
20 </tr>
21 <tr>
22 <td width="10%" align="left" valign="top"><a href="pgtcl-pgloexport.html" accesskey="P">Prev</a></td>
23 <td width="10%" align="left" valign="top"><a href="pgtcl-pgloexport.html">Fast Backward</a></td>
24 <td width="60%" align="center" valign="bottom"></td>
25 <td width="10%" align="right" valign="top"><a href="pgtcl-pgcopycomplete.html">Fast Forward</a></td>
26 <td width="10%" align="right" valign="top"><a href="pgtcl-pgcopycomplete.html" accesskey="N">Next</a></td>
27 </tr>
28 </table>
29 <hr align="left" width="100%"></div>
30 <h1><a name="PGTCL-PGSQLITE" id="PGTCL-PGSQLITE"></a>pg_sqlite</h1>
31 <div class="REFNAMEDIV"><a name="AEN2338" id="AEN2338"></a>
32 <h2>Name</h2>
33 pg_sqlite&nbsp;--&nbsp;implements a bridge between PostgreSQL and Sqlite3 using the Pgtcl and sqlite3 packages. <a name="IX-PGTCL-SQLITE2-2" id="IX-PGTCL-SQLITE2-2"></a></div>
34 <div class="REFSYNOPSISDIV"><a name="AEN2343" id="AEN2343"></a>
35 <h2>Synopsis</h2>
36 <pre class="SYNOPSIS">pg_sqlite <code class="PARAMETER">sqlite_db</code> <code class="PARAMETER">command</code> [<span class="OPTIONAL">args</span>]</pre></div>
37 <div class="REFSECT1"><a name="AEN2348" id="AEN2348"></a>
38 <h2>Description</h2>
39 <p><code class="FUNCTION">pg_sqlite</code> can import the results of a Postgres SQL query (previously made via <code class="FUNCTION">pg_exec</code>) directly into an sqlite3 table, export the results of an Sqlite SQL query into a Postgres table (via <tt class="LITERAL">write_tabsep</tt>), or import TSV files directly into sqlite3.</p>
40 <p>The commands currently implemented are import_postgres_result, read_tabsep, write_tabsep, and read_tabsep_keylist.</p>
41 </div>
42 <div class="REFSECT1"><a name="AEN2355" id="AEN2355"></a>
43 <h2>Arguments</h2>
44 <div class="VARIABLELIST">
45 <dl>
46 <dt><code class="PARAMETER">sqlite_db</code></dt>
47 <dd>
48 <p>An Sqlite3 database handle previously created via the <tt class="LITERAL">sqlite3</tt> command.</p>
49 </dd>
50 <dt><code class="PARAMETER">command</code></dt>
51 <dd>
52 <p>The command, one of <tt class="LITERAL">info</tt>, <tt class="LITERAL">import_postgres_result</tt>, <tt class="LITERAL">read_tabsep</tt>, <tt class="LITERAL">write_tabsep</tt>, or <tt class="LITERAL">read_tabsep_keylist</tt>,</p>
53 </dd>
54 <dt><code class="PARAMETER">args</code></dt>
55 <dd>
56 <p>Command-specific arguments.</p>
57 </dd>
58 </dl>
59 </div>
60 </div>
61 <div class="REFSECT1"><a name="AEN2379" id="AEN2379"></a>
62 <h2>Commands</h2>
63 <p><tt class="COMMAND">info</tt></p>
64 <pre class="SYNOPSIS"> <code class="FUNCTION">pg_sqlite</code> <code class="PARAMETER">sqlite_db</code> info
65 ?<span class="OPTIONAL">-busy</span>?
66 ?<span class="OPTIONAL">-filename</span>?
67 ?<span class="OPTIONAL">-db <code class="PARAMETER">database_name</code></span>?
68 </pre>
69 <p>Request information from an SQLITE database connection. Returns a key-value list containing the values requested if available. With no arguments, all available info is returned.</p>
70 <div class="VARIABLELIST">
71 <dl>
72 <dt>-filename</dt>
73 <dd>
74 <p>Request the filename associated with a database.</p>
75 </dd>
76 <dt>-db <code class="PARAMETER">database</code></dt>
77 <dd>
78 <p>For the -filename option, specify the database name (default "main").</p>
79 </dd>
80 <dt>-busy</dt>
81 <dd>
82 <p>Request a list of prepared commands that are currently busy.</p>
83 </dd>
84 </dl>
85 </div>
86 <p><tt class="COMMAND">import_postgres_result</tt></p>
87 <pre class="SYNOPSIS"> <code class="FUNCTION">pg_sqlite</code> <code class="PARAMETER">sqlite_db</code> import_postgres_result <code class="PARAMETER">handle</code>
88 ?<span class="OPTIONAL">-rowbyrow</span>?
89 ?<span class="OPTIONAL">-sql <code class="PARAMETER">target_sql</code></span>?
90 ?<span class="OPTIONAL">-create <code class="PARAMETER">new_table</code></span>?
91 ?<span class="OPTIONAL">-into <code class="PARAMETER">table</code></span>?
92 ?<span class="OPTIONAL">-replace</span>?
93 ?<span class="OPTIONAL">-as <code class="PARAMETER">name_type_list</code></span>?
94 ?<span class="OPTIONAL">-types <code class="PARAMETER">type_list</code></span>?
95 ?<span class="OPTIONAL">-names <code class="PARAMETER">name_list</code></span>?
96 ?<span class="OPTIONAL">-pkey <code class="PARAMETER">primary_key</code></span>?
97 ?<span class="OPTIONAL">-sep <code class="PARAMETER">separator</code></span>?
98 ?<span class="OPTIONAL">-null <code class="PARAMETER">null_string</code></span>?
99 ?<span class="OPTIONAL">-poll_interval <code class="PARAMETER">rows</code></span>?
100 ?<span class="OPTIONAL">-recommit <code class="PARAMETER">rows</code></span>?
101 ?<span class="OPTIONAL">-check</span>?
102 ?<span class="OPTIONAL">-max <code class="PARAMETER">column-name variable-name</code></span>?
103 </pre>
104 <p>Import the result of a PostgreSQL request into an sqlite3 table.</p>
105 <div class="VARIABLELIST">
106 <dl>
107 <dt><code class="PARAMETER">handle</code></dt>
108 <dd>
109 <p>A database or result handle. Normally, you would call <code class="FUNCTION">pg_exec</code> and pass the result handle to <code class="FUNCTION">pg_sqlite</code> here. If you are using row_by_row mode, though, you use pg_sendquery and pass the PostgreSQL database handle here.</p>
110 </dd>
111 <dt>-rowbyrow</dt>
112 <dd>
113 <p>Perform the request using row-by-row mode. This injects the data to sqlite directly without making an internal copy, but the result may be incomplete or inconsistent if an error occurs during the request.</p>
114 </dd>
115 <dt>-sep <code class="PARAMETER">separator</code></dt>
116 <dd>
117 <p>String to use to separate columns. Default is "\t" (tab).</p>
118 </dd>
119 <dt>-null <code class="PARAMETER">null_string</code></dt>
120 <dd>
121 <p>String to use to indicate a null value. Default is to treat all strings literally.</p>
122 </dd>
123 <dt>-sql <code class="PARAMETER">target_sql</code></dt>
124 <dd>
125 <p>An INSERT statement, suitable to be compiled into a prepared statement to be applied to each row. For example "INSERT INTO newtable (id, name, value) VALUES (?,?,?)"</p>
126 </dd>
127 <dt>-create <code class="PARAMETER">new_table</code></dt>
128 <dd>
129 <p>A table to be created in sqlite. The names and types of columns, and the primary key, must be provided.</p>
130 </dd>
131 <dt>-into <code class="PARAMETER">table</code></dt>
132 <dd>
133 <p>An existing sqlite table to insert the data. The names of the columns must be provided, if the type can not be inferred it will be assumed to be "text".</p>
134 </dd>
135 <dt>-replace</dt>
136 <dd>
137 <p>When performing the insert on an existing or newly create table, use "INSERT OR REPLACE" semantics. Not compatible with "-sql".</p>
138 </dd>
139 <dt>-as <code class="PARAMETER">name-type-list</code></dt>
140 <dd>
141 <p>A list of alternating column names and types. See note on types.</p>
142 </dd>
143 <dt>-types <code class="PARAMETER">type-list</code></dt>
144 <dd>
145 <p>A list of column types. See note on types.</p>
146 </dd>
147 <dt>-names <code class="PARAMETER">name-list</code></dt>
148 <dd>
149 <p>A list of column names.</p>
150 </dd>
151 <dt>-pkey <code class="PARAMETER">primary_key</code></dt>
152 <dd>
153 <p>A list containing key names and optional sorting to indicate primary key where needed. For example <tt class="COMMAND">-pkey {{clock ASC} {sequence ASC}}</tt>.</p>
154 </dd>
155 <dt>-poll_interval <code class="PARAMETER">count</code></dt>
156 <dd>
157 <p>Call DoOneEvent() every <code class="PARAMETER">count</code> rows to keep the event loop alive during long transactions.</p>
158 </dd>
159 <dt>-recommit <code class="PARAMETER">count</code></dt>
160 <dd>
161 <p>Chunk the operation in transactions, with one transaction every <code class="PARAMETER">count</code> rows.</p>
162 </dd>
163 <dt>-check</dt>
164 <dd>
165 <p>Check (via a SELECT) whether the exact row is already present, and skip inserting the row if so. This avoids bloating the WAL log during large re-loads of databases, at some performance cost.</p>
166 </dd>
167 <dt>-max <code class="PARAMETER">column-name variable-name</code></dt>
168 <dd>
169 <p>Set $variable-name to the maximum value of column-name imported.</p>
170 </dd>
171 </dl>
172 </div>
173 <p><tt class="COMMAND">write_tabsep</tt></p>
174 <pre class="SYNOPSIS"> <code class="FUNCTION">pg_sqlite</code> <code class="PARAMETER">sqlite_db</code> write_tabsep <code class="PARAMETER">handle</code> <code class="PARAMETER">sql</code>
175 ?<span class="OPTIONAL"><code class="PARAMETER">sql</code></span>?
176 ?<span class="OPTIONAL">-sep <code class="PARAMETER">separator</code></span>?
177 ?<span class="OPTIONAL">-null <code class="PARAMETER">null_string</code></span>?
178 ?<span class="OPTIONAL">-poll_interval <code class="PARAMETER">rows</code></span>?
179 </pre>
180 <p>Write the results of the provided <code class="PARAMETER">sql</code> to a file handle</p>
181 <p>This command may be used to export sqlite3 data to postgres. You issue a <tt class="COMMAND">COPY FROM STDIN ... FORMAT text</tt> command, then use <tt class="COMMAND">pg_sqlite write_tabsep ...</tt> to write the data directly to the Postgresql handle, followed by writing the terminator line to the same handle. See the PostgreSQL documentation on the "COPY" command for more details.</p>
182 <div class="VARIABLELIST">
183 <dl>
184 <dt><code class="PARAMETER">handle</code></dt>
185 <dd>
186 <p>File handle.</p>
187 </dd>
188 <dt>-sep <code class="PARAMETER">separator</code></dt>
189 <dd>
190 <p>String to use to separate columns. Default is "\t" (tab).</p>
191 </dd>
192 <dt>-null <code class="PARAMETER">null_string</code></dt>
193 <dd>
194 <p>String to use to indicate a null value. Default is to treat all strings literally.</p>
195 </dd>
196 <dt>-poll_interval <code class="PARAMETER">count</code></dt>
197 <dd>
198 <p>Call DoOneEvent() every <code class="PARAMETER">count</code> rows to keep the event loop alive during long transactions.</p>
199 </dd>
200 </dl>
201 </div>
202 <p><tt class="COMMAND">read_tabsep</tt></p>
203 <pre class="SYNOPSIS"> <code class="FUNCTION">pg_sqlite</code> <code class="PARAMETER">sqlite_db</code> read_tabsep
204 ?<span class="OPTIONAL">-row <code class="PARAMETER">single_tab_separated_row</code></span>?
205 ?<span class="OPTIONAL">-file <code class="PARAMETER">file_handle</code></span>?
206 ?<span class="OPTIONAL">-sql <code class="PARAMETER">target_sql</code></span>?
207 ?<span class="OPTIONAL">-create <code class="PARAMETER">new_table</code></span>?
208 ?<span class="OPTIONAL">-into <code class="PARAMETER">table</code></span>?
209 ?<span class="OPTIONAL">-replace</span>?
210 ?<span class="OPTIONAL">-as <code class="PARAMETER">name_type_list</code></span>?
211 ?<span class="OPTIONAL">-types <code class="PARAMETER">type_list</code></span>?
212 ?<span class="OPTIONAL">-names <code class="PARAMETER">name_list</code></span>?
213 ?<span class="OPTIONAL">-pkey <code class="PARAMETER">primary_key</code></span>?
214 ?<span class="OPTIONAL">-sep <code class="PARAMETER">separator</code></span>?
215 ?<span class="OPTIONAL">-null <code class="PARAMETER">null_string</code></span>?
216 ?<span class="OPTIONAL">-poll_interval <code class="PARAMETER">rows</code></span>?
217 ?<span class="OPTIONAL">-recommit <code class="PARAMETER">rows</code></span>?
218 ?<span class="OPTIONAL">-check</span>?
219 </pre>
220 <p>Read a previously opened file into an sqlite3 table.</p>
221 <div class="VARIABLELIST">
222 <dl>
223 <dt>-row <code class="PARAMETER">single_tab_separated_row</code></dt>
224 <dd>
225 <p>An already read tab-separated line.</p>
226 </dd>
227 <dt>-file <code class="PARAMETER">file_handle</code></dt>
228 <dd>
229 <p>An open file consistion of tab-separated rows.</p>
230 </dd>
231 <dt>-sep <code class="PARAMETER">separator</code></dt>
232 <dd>
233 <p>String to use to separate columns. Default is "\t" (tab).</p>
234 </dd>
235 <dt>-null <code class="PARAMETER">null_string</code></dt>
236 <dd>
237 <p>String to use to indicate a null value. Default is to treat all strings literally.</p>
238 </dd>
239 <dt>-sql <code class="PARAMETER">target_sql</code></dt>
240 <dd>
241 <p>An INSERT statement, suitable to be compiled into a prepared statement to be applied to each row. For example "INSERT INTO newtable (id, name, value) VALUES (?,?,?)"</p>
242 </dd>
243 <dt>-create <code class="PARAMETER">new_table</code></dt>
244 <dd>
245 <p>A table to be created in sqlite. The names and types of columns, and the primary key, must be provided.</p>
246 </dd>
247 <dt>-into <code class="PARAMETER">table</code></dt>
248 <dd>
249 <p>An existing sqlite table to insert the data. The names of the columns must be provided, if the type can not be inferred it will be assumed to be "text".</p>
250 </dd>
251 <dt>-replace</dt>
252 <dd>
253 <p>When performing the insert on an existing or newly create table, use "INSERT OR REPLACE" semantics. Not compatible with "-sql".</p>
254 </dd>
255 <dt>-as <code class="PARAMETER">name-type-list</code></dt>
256 <dd>
257 <p>A list of alternating column names and types. See note on types.</p>
258 </dd>
259 <dt>-types <code class="PARAMETER">type-list</code></dt>
260 <dd>
261 <p>A list of column types. See note on types.</p>
262 </dd>
263 <dt>-names <code class="PARAMETER">name-list</code></dt>
264 <dd>
265 <p>A list of column names.</p>
266 </dd>
267 <dt>-pkey <code class="PARAMETER">primary_key</code></dt>
268 <dd>
269 <p>A list containing key names and optional sorting to indicate primary key where needed. For example <tt class="COMMAND">-pkey {{clock ASC} {sequence ASC}}</tt>.</p>
270 </dd>
271 <dt>-poll_interval <code class="PARAMETER">count</code></dt>
272 <dd>
273 <p>Call DoOneEvent() every <code class="PARAMETER">count</code> rows to keep the event loop alive during long transactions.</p>
274 </dd>
275 <dt>-recommit <code class="PARAMETER">count</code></dt>
276 <dd>
277 <p>Chunk the operation in transactions, with one transaction every <code class="PARAMETER">count</code> rows.</p>
278 </dd>
279 <dt>-check</dt>
280 <dd>
281 <p>Check (via a SELECT) whether the exact row is already present, and skip inserting the row if so. This avoids bloating the WAL log during large re-loads of databases, at some performance cost.</p>
282 </dd>
283 </dl>
284 </div>
285 <p><tt class="COMMAND">read_tabsep_keylist</tt></p>
286 <pre class="SYNOPSIS"> <code class="FUNCTION">pg_sqlite</code> <code class="PARAMETER">sqlite_db</code> read_tabsep_keylist
287 ?<span class="OPTIONAL">-row <code class="PARAMETER">single_tab_separated_row</code></span>?
288 ?<span class="OPTIONAL">-file <code class="PARAMETER">file_handle</code></span>?
289 ?<span class="OPTIONAL">-create <code class="PARAMETER">new_table</code></span>?
290 ?<span class="OPTIONAL">-into <code class="PARAMETER">table</code></span>?
291 ?<span class="OPTIONAL">-replace</span>?
292 ?<span class="OPTIONAL">-as <code class="PARAMETER">name_type_list</code></span>?
293 ?<span class="OPTIONAL">-names <code class="PARAMETER">name_list</code></span>?
294 ?<span class="OPTIONAL">-pkey <code class="PARAMETER">primary_key</code></span>?
295 ?<span class="OPTIONAL">-sep <code class="PARAMETER">separator</code></span>?
296 ?<span class="OPTIONAL">-null <code class="PARAMETER">null_string</code></span>?
297 ?<span class="OPTIONAL">-poll_interval <code class="PARAMETER">rows</code></span>?
298 ?<span class="OPTIONAL">-recommit <code class="PARAMETER">rows</code></span>?
299 </pre>
300 <p>Read a previously opened file containing alternating key-value columns into an sqlite3 table.</p>
301 <div class="VARIABLELIST">
302 <dl>
303 <dt>-row <code class="PARAMETER">single_tab_separated_row</code></dt>
304 <dd>
305 <p>An already read tab-separated key-value list line.</p>
306 </dd>
307 <dt>-file <code class="PARAMETER">file_handle</code></dt>
308 <dd>
309 <p>An open file consistion of tab-separated key-value list rows.</p>
310 </dd>
311 <dt>-sep <code class="PARAMETER">separator</code></dt>
312 <dd>
313 <p>String to use to separate columns. Default is "\t" (tab).</p>
314 </dd>
315 <dt>-null <code class="PARAMETER">null_string</code></dt>
316 <dd>
317 <p>String to use to indicate a null value. Default is to treat all strings literally.</p>
318 </dd>
319 <dt>-create <code class="PARAMETER">new_table</code></dt>
320 <dd>
321 <p>A table to be created in sqlite. The names and types of columns, and the primary key, must be provided.</p>
322 </dd>
323 <dt>-into <code class="PARAMETER">table</code></dt>
324 <dd>
325 <p>An existing sqlite table to insert the data. The names of the columns must be provided, if the type can not be inferred it will be assumed to be "text".</p>
326 </dd>
327 <dt>-replace</dt>
328 <dd>
329 <p>When performing the insert on an existing or newly create table, use "INSERT OR REPLACE" semantics. Not compatible with "-sql".</p>
330 </dd>
331 <dt>-as <code class="PARAMETER">name-type-list</code></dt>
332 <dd>
333 <p>A list of alternating column names and types. See note on types.</p>
334 </dd>
335 <dt>-names <code class="PARAMETER">name-list</code></dt>
336 <dd>
337 <p>A list of column names.</p>
338 </dd>
339 <dt>-pkey <code class="PARAMETER">primary_key</code></dt>
340 <dd>
341 <p>A list containing key names and optional sorting to indicate primary key where needed. For example <tt class="COMMAND">-pkey {{clock ASC} {sequence ASC}}</tt>.</p>
342 </dd>
343 <dt>-poll_interval <code class="PARAMETER">count</code></dt>
344 <dd>
345 <p>Call DoOneEvent() every <code class="PARAMETER">count</code> rows to keep the event loop alive during long transactions.</p>
346 </dd>
347 <dt>-recommit <code class="PARAMETER">count</code></dt>
348 <dd>
349 <p>Chunk the operation in transactions, with one transaction every <code class="PARAMETER">count</code> rows.</p>
350 </dd>
351 </dl>
352 </div>
353 </div>
354 <div class="REFSECT1"><a name="AEN2767" id="AEN2767"></a>
355 <h2>Types</h2>
356 <p><span class="emphasis"><i class="EMPHASIS">A note on types:</i></span> <code class="FUNCTION">pg_sqlite</code> supports four types: <tt class="LITERAL">integer</tt> (or int), <tt class="LITERAL">boolean</tt> (or bool), <tt class="LITERAL">double</tt> (or real), and <tt class="LITERAL">text</tt>. <tt class="LITERAL">Integer</tt>, <tt class="LITERAL">double</tt>, and <tt class="LITERAL">text</tt> match both sqlite and postgresql types. <tt class="LITERAL">Boolean</tt> is an integer type in sqlite, and boolean in postgresql, and converts postgresql boolean values (such as 'yes', 'no', 'true', or 'false') to integer 1 and 0.</p>
357 <p>In addition, <code class="FUNCTION">pg_sqlite</code> will accept PostgreSQL boolean values for the integer type. This may be made conditional on a "strict" mode in the future.</p>
358 </div>
359 <div class="REFSECT1"><a name="AEN2782" id="AEN2782"></a>
360 <h2>Return Value</h2>
361 <p>Number of rows imported or exported.</p>
362 </div>
363 <div class="REFSECT1"><a name="AEN2785" id="AEN2785"></a>
364 <h2>See Also</h2>
365 <p><span class="PRODUCTNAME">Sqlite 3</span></p>
366 </div>
367 <div class="NAVFOOTER">
368 <hr align="left" width="100%">
369 <table summary="Footer navigation table" width="100%" border="0" cellpadding="0" cellspacing="0">
370 <tr>
371 <td width="33%" align="left" valign="top"><a href="pgtcl-pgloexport.html" accesskey="P">Prev</a></td>
372 <td width="34%" align="center" valign="top"><a href="index.html" accesskey="H">Home</a></td>
373 <td width="33%" align="right" valign="top"><a href="pgtcl-pgcopycomplete.html" accesskey="N">Next</a></td>
374 </tr>
375 <tr>
376 <td width="33%" align="left" valign="top">pg_lo_export</td>
377 <td width="34%" align="center" valign="top"><a href="libpgtcl-ref.html" accesskey="U">Up</a></td>
378 <td width="33%" align="right" valign="top">pg_copy_complete</td>
379 </tr>
380 </table>
381 </div>
382 </body>
383 </html>