| PostgreSQL Tcl Interface Documentation | ||||
|---|---|---|---|---|
| Prev | Fast Backward | Fast Forward | Next | |
pg_sqlite can import the results of a Postgres SQL query (previously made via pg_exec) directly into an sqlite3 table, export the results of an Sqlite SQL query into a Postgres table (via write_tabsep), or import TSV files directly into sqlite3.
The commands currently implemented are import_postgres_result, read_tabsep, write_tabsep, and read_tabsep_keylist.
sqlite_dbAn Sqlite3 database handle previously created via the sqlite3 command.
commandThe command, one of info, import_postgres_result, read_tabsep, write_tabsep, or read_tabsep_keylist,
argsCommand-specific arguments.
info
pg_sqlitesqlite_dbinfo ?-busy? ?-filename? ?-dbdatabase_name?
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.
Request the filename associated with a database.
databaseFor the -filename option, specify the database name (default "main").
Request a list of prepared commands that are currently busy.
import_postgres_result
pg_sqlitesqlite_dbimport_postgres_resulthandle?-rowbyrow? ?-sqltarget_sql? ?-createnew_table? ?-intotable? ?-replace? ?-asname_type_list? ?-typestype_list? ?-namesname_list? ?-pkeyprimary_key? ?-sepseparator? ?-nullnull_string? ?-poll_intervalrows? ?-recommitrows? ?-check? ?-maxcolumn-name variable-name?
Import the result of a PostgreSQL request into an sqlite3 table.
handleA database or result handle. Normally, you would call pg_exec and pass the result handle to pg_sqlite here. If you are using row_by_row mode, though, you use pg_sendquery and pass the PostgreSQL database handle here.
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.
separatorString to use to separate columns. Default is "\t" (tab).
null_stringString to use to indicate a null value. Default is to treat all strings literally.
target_sqlAn 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 (?,?,?)"
new_tableA table to be created in sqlite. The names and types of columns, and the primary key, must be provided.
tableAn 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".
When performing the insert on an existing or newly create table, use "INSERT OR REPLACE" semantics. Not compatible with "-sql".
name-type-listA list of alternating column names and types. See note on types.
type-listA list of column types. See note on types.
name-listA list of column names.
primary_keyA list containing key names and optional sorting to indicate primary key where needed. For example -pkey {{clock ASC} {sequence ASC}}.
countCall DoOneEvent() every count rows to keep the event loop alive during long transactions.
countChunk the operation in transactions, with one transaction every count rows.
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.
column-name variable-nameSet $variable-name to the maximum value of column-name imported.
write_tabsep
pg_sqlitesqlite_dbwrite_tabsephandlesql?sql? ?-sepseparator? ?-nullnull_string? ?-poll_intervalrows?
Write the results of the provided sql to a file handle
This command may be used to export sqlite3 data to postgres. You issue a COPY FROM STDIN ... FORMAT text command, then use pg_sqlite write_tabsep ... 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.
handleFile handle.
separatorString to use to separate columns. Default is "\t" (tab).
null_stringString to use to indicate a null value. Default is to treat all strings literally.
countCall DoOneEvent() every count rows to keep the event loop alive during long transactions.
read_tabsep
pg_sqlitesqlite_dbread_tabsep ?-rowsingle_tab_separated_row? ?-filefile_handle? ?-sqltarget_sql? ?-createnew_table? ?-intotable? ?-replace? ?-asname_type_list? ?-typestype_list? ?-namesname_list? ?-pkeyprimary_key? ?-sepseparator? ?-nullnull_string? ?-poll_intervalrows? ?-recommitrows? ?-check?
Read a previously opened file into an sqlite3 table.
single_tab_separated_rowAn already read tab-separated line.
file_handleAn open file consistion of tab-separated rows.
separatorString to use to separate columns. Default is "\t" (tab).
null_stringString to use to indicate a null value. Default is to treat all strings literally.
target_sqlAn 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 (?,?,?)"
new_tableA table to be created in sqlite. The names and types of columns, and the primary key, must be provided.
tableAn 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".
When performing the insert on an existing or newly create table, use "INSERT OR REPLACE" semantics. Not compatible with "-sql".
name-type-listA list of alternating column names and types. See note on types.
type-listA list of column types. See note on types.
name-listA list of column names.
primary_keyA list containing key names and optional sorting to indicate primary key where needed. For example -pkey {{clock ASC} {sequence ASC}}.
countCall DoOneEvent() every count rows to keep the event loop alive during long transactions.
countChunk the operation in transactions, with one transaction every count rows.
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.
read_tabsep_keylist
pg_sqlitesqlite_dbread_tabsep_keylist ?-rowsingle_tab_separated_row? ?-filefile_handle? ?-createnew_table? ?-intotable? ?-replace? ?-asname_type_list? ?-namesname_list? ?-pkeyprimary_key? ?-sepseparator? ?-nullnull_string? ?-poll_intervalrows? ?-recommitrows?
Read a previously opened file containing alternating key-value columns into an sqlite3 table.
single_tab_separated_rowAn already read tab-separated key-value list line.
file_handleAn open file consistion of tab-separated key-value list rows.
separatorString to use to separate columns. Default is "\t" (tab).
null_stringString to use to indicate a null value. Default is to treat all strings literally.
new_tableA table to be created in sqlite. The names and types of columns, and the primary key, must be provided.
tableAn 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".
When performing the insert on an existing or newly create table, use "INSERT OR REPLACE" semantics. Not compatible with "-sql".
name-type-listA list of alternating column names and types. See note on types.
name-listA list of column names.
primary_keyA list containing key names and optional sorting to indicate primary key where needed. For example -pkey {{clock ASC} {sequence ASC}}.
countCall DoOneEvent() every count rows to keep the event loop alive during long transactions.
countChunk the operation in transactions, with one transaction every count rows.
A note on types: pg_sqlite supports four types: integer (or int), boolean (or bool), double (or real), and text. Integer, double, and text match both sqlite and postgresql types. Boolean 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.
In addition, pg_sqlite will accept PostgreSQL boolean values for the integer type. This may be made conditional on a "strict" mode in the future.