Skip to content

Commit 3013f68

Browse files
committed
README.md, many fixes
1 parent 4740723 commit 3013f68

1 file changed

Lines changed: 47 additions & 32 deletions

File tree

README.md

Lines changed: 47 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ SQLite Foreign Data Wrapper for PostgreSQL
44
This is a foreign data wrapper (FDW) to connect [PostgreSQL](https://www.postgresql.org/)
55
to [SQLite](https://sqlite.org/) database file. This FDW works with PostgreSQL 11, 12, 13, 14, 15 and confirmed with SQLite 3.38.5.
66

7+
<img src="https://upload.wikimedia.org/wikipedia/commons/2/29/Postgresql_elephant.svg" align="center" height="100" alt="PostgreSQL"/> + <img src="https://upload.wikimedia.org/wikipedia/commons/3/38/SQLite370.svg" align="center" height="100" alt="SQLite"/>
8+
79
Contents
810
--------
911

@@ -137,7 +139,7 @@ Just ensure `postgres` OS user have permissions for reading or writing on SQLite
137139
`sqlite_fdw` accepts the following table-level options via the
138140
`CREATE FOREIGN TABLE` command:
139141

140-
- **table** as *string*, optioanl
142+
- **table** as *string*, optional
141143

142144
SQLite table name. Use if not equal to name of foreign table in PostgreSQL. Also see about [identifier case handling](#identifier-case-handling).
143145

@@ -216,21 +218,12 @@ This SQL isn't correct for SQLite: `Error: duplicate column name: a`, but is cor
216218
For SQLite there is no difference between
217219

218220
```sql
219-
SELECT *
220-
FROM t;
221-
SELECT *
222-
FROM T;
223-
SELECT *
224-
FROM "t";
225-
SELECT *
226-
FROM "T";
227-
```
228-
For PostgreSQL
229-
```sql
230-
SELECT *
231-
FROM "T";
221+
SELECT * FROM t; -- №1
222+
SELECT * FROM T; -- №2
223+
SELECT * FROM "t"; -- №3
224+
SELECT * FROM "T"; -- №4
232225
```
233-
is independend query to table `T`, not to table `t` as first queries from previous example.
226+
For PostgreSQL the query with comment `№4` is independend query to table `T`, not to table `t` as other queries.
234227

235228
If there is
236229

@@ -240,7 +233,7 @@ If there is
240233
b REAL
241234
);
242235
```
243-
in SQLite, both `a` and `A` , `b` and `B` columns will have the same real datasource in SQlite
236+
in SQLite, both `a` and `A` , `b` and `B` columns will have the same real datasource in SQlite in follow foreign table:
244237

245238
```sql
246239
CREATE FOREIGN TABLE "SQLite test" (
@@ -259,7 +252,7 @@ Generated columns
259252
SQLite provides support for [generated columns](https://www.sqlite.org/gencol.html).
260253
Behaviour of `sqlite_fdw` with this columns _isn't yet described_.
261254

262-
Note that while `sqlite_fdw` will `insert` or `update` the generated column value
255+
Note that while `sqlite_fdw` will `INSERT` or `UPDATE` the generated column value
263256
in SQLite, there is nothing to stop the value being modified within SQLite,
264257
and hence no guarantee that in subsequent `SELECT` operations the column will
265258
still contain the expected generated value. This limitation also applies to
@@ -285,33 +278,47 @@ Examples
285278

286279
### Install the extension:
287280

281+
Once for a database you need, as PostgreSQL superuser.
282+
288283
```sql
289284
CREATE EXTENSION sqlite_fdw;
290285
```
291286

292287
### Create a foreign server with appropriate configuration:
293288

294-
Please specify SQLite database path using `database` option.
289+
Once for a foreign datasource you need, as PostgreSQL superuser. Please specify SQLite database path using `database` option.
295290

296291
```sql
297292
CREATE SERVER sqlite_server
298-
FOREIGN DATA WRAPPER sqlite_fdw
299-
OPTIONS (
300-
database '/path/to/database'
301-
);
293+
FOREIGN DATA WRAPPER sqlite_fdw
294+
OPTIONS (
295+
database '/path/to/database'
296+
);
297+
```
298+
299+
### Grant usage on foreign server to normal user in PostgreSQL:
300+
301+
Once for a normal user (non-superuser) in PostgreSQL, as PostgreSQL superuser. It is a good idea to use a superuser only where really necessary, so let's allow a normal user to use the foreign server (this is not required for the example to work, but it's secirity recomedation).
302+
303+
```sql
304+
GRANT USAGE ON FOREIGN SERVER sqlite_server TO pguser;
302305
```
306+
Where `pguser` is a sample user for works with foreign server (and foreign tables).
303307

304308
### User mapping
305309

306310
There is no user or password conceptions in SQlite, hence `sqlite_fdw` no need any `CREATE USER MAPPING` command.
307311

308312
### Create foreign table
313+
All `CREATE FOREIGN TABLE` SQL commands can be executed as a normal PostgreSQL user if there were correct `GRANT USAGE ON FOREIGN SERVER`. No need PostgreSQL supersuer for secirity reasons but also works with PostgreSQL supersuer.
314+
309315
Please specify `table` option if SQLite table name is different from foreign table name.
310316

311317
```sql
312318
CREATE FOREIGN TABLE t1 (
313319
a integer,
314-
b text)
320+
b text
321+
)
315322
SERVER sqlite_server
316323
OPTIONS (
317324
table 't1_sqlite'
@@ -323,7 +330,8 @@ If you want to update tables, please add `OPTIONS (key 'true')` to a primary key
323330
```sql
324331
CREATE FOREIGN TABLE t1(
325332
a integer OPTIONS (key 'true'),
326-
b text)
333+
b text
334+
)
327335
SERVER sqlite_server
328336
OPTIONS (
329337
table 't1_sqlite'
@@ -336,7 +344,8 @@ If you need to convert INT SQLite column (epoch Unix Time) to be treated/visuali
336344
CREATE FOREIGN TABLE t1(
337345
a integer,
338346
b text,
339-
c timestamp without time zone OPTIONS (column_type 'INT'))
347+
c timestamp without time zone OPTIONS (column_type 'INT')
348+
)
340349
SERVER sqlite_server
341350
OPTIONS (
342351
table 't1_sqlite'
@@ -350,6 +359,7 @@ As above, but with aliased column names:
350359
a integer,
351360
b text OPTIONS (column_name 'test_id'),
352361
c timestamp without time zone OPTIONS (column_type 'INT', column_name 'unixtime')
362+
)
353363
SERVER sqlite_server
354364
OPTIONS (
355365
table 't1_sqlite'
@@ -360,8 +370,8 @@ As above, but with aliased column names:
360370

361371
```sql
362372
IMPORT FOREIGN SCHEMA someschema
363-
FROM SERVER sqlite_server;
364-
INTO public;
373+
FROM SERVER sqlite_server
374+
INTO public;
365375
```
366376

367377
Note: `someschema` has no particular meaning and can be set to an arbitrary value.
@@ -370,19 +380,25 @@ Note: `someschema` has no particular meaning and can be set to an arbitrary valu
370380
For the table from previous examples
371381

372382
```sql
373-
SELECT *
374-
FROM t1;
383+
SELECT * FROM t1;
375384
```
376385

377386
Limitations
378387
-----------
379388

389+
### SQL commands
380390
- `COPY` command for foreign tables is not supported
381391
- `IMPORT` of generated column is not supported
382-
- Insert into a partitioned table which has foreign partitions is not supported. Error "Not support partition insert" will display.
392+
- `INSERT` into a partitioned table which has foreign partitions is not supported. Error `Not support partition insert` will display.
383393
- `TRUNCATE` in `sqlite_fdw` always delete data of both parent and child tables (no matter user inputs `TRUNCATE table CASCADE` or `TRUNCATE table RESTRICT`) if there are foreign-keys references with `ON DELETE CASCADE` clause.
384394
- `RETURNING` is not supported.
385-
- `sqlite_fdw` only supports `ARRAY` const, for example, `ANY (ARRAY[1, 2, 3])` or `ANY ('{1, 2 ,3}')`. `Sqlite_fdw` does not support `ARRAY` expression, for example, `ANY (ARRAY[c1, 1, c1+0])`. For `ANY(ARRAY)` clause, `sqlite_fdw` deparses it using `IN` operator.
395+
396+
### Arrays
397+
- `sqlite_fdw` only supports `ARRAY` const, for example, `ANY (ARRAY[1, 2, 3])` or `ANY ('{1, 2 ,3}')`.
398+
- `sqlite_fdw` does not support `ARRAY` expression, for example, `ANY (ARRAY[c1, 1, c1+0])`.
399+
- For `ANY(ARRAY)` clause, `sqlite_fdw` deparses it using `IN` operator.
400+
401+
### Numbers (range and precision)
386402
- For `sum` function of SQLite, output of `sum(bigint)` is `integer` value. If input values are big, the overflow error may occurs on SQLite because it overflow within the range of signed 64bit. For PostgreSQL, it can calculate as over the precision of `bigint`, so overflow does not occur.
387403
- SQLite promises to preserve the 15 most significant digits of a floating point value. The big value which exceed 15 most significant digits may become different value after inserted.
388404
- SQLite does not support `numeric` type as PostgreSQL. Therefore, it does not allow to store numbers with too high precision and scale. Error out of range occurs.
@@ -394,7 +410,6 @@ Tests
394410
Contributing
395411
------------
396412

397-
## Contributing
398413
Opening issues and pull requests on GitHub are welcome.
399414

400415
Useful links

0 commit comments

Comments
 (0)