You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -137,7 +139,7 @@ Just ensure `postgres` OS user have permissions for reading or writing on SQLite
137
139
`sqlite_fdw` accepts the following table-level options via the
138
140
`CREATE FOREIGN TABLE` command:
139
141
140
-
-**table** as *string*, optioanl
142
+
-**table** as *string*, optional
141
143
142
144
SQLite table name. Use if not equal to name of foreign table in PostgreSQL. Also see about [identifier case handling](#identifier-case-handling).
143
145
@@ -216,21 +218,12 @@ This SQL isn't correct for SQLite: `Error: duplicate column name: a`, but is cor
216
218
For SQLite there is no difference between
217
219
218
220
```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
232
225
```
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.
234
227
235
228
If there is
236
229
@@ -240,7 +233,7 @@ If there is
240
233
b REAL
241
234
);
242
235
```
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:
244
237
245
238
```sql
246
239
CREATE FOREIGN TABLE "SQLite test" (
@@ -259,7 +252,7 @@ Generated columns
259
252
SQLite provides support for [generated columns](https://www.sqlite.org/gencol.html).
260
253
Behaviour of `sqlite_fdw` with this columns _isn't yet described_.
261
254
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
263
256
in SQLite, there is nothing to stop the value being modified within SQLite,
264
257
and hence no guarantee that in subsequent `SELECT` operations the column will
265
258
still contain the expected generated value. This limitation also applies to
@@ -285,33 +278,47 @@ Examples
285
278
286
279
### Install the extension:
287
280
281
+
Once for a database you need, as PostgreSQL superuser.
282
+
288
283
```sql
289
284
CREATE EXTENSION sqlite_fdw;
290
285
```
291
286
292
287
### Create a foreign server with appropriate configuration:
293
288
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.
295
290
296
291
```sql
297
292
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;
302
305
```
306
+
Where `pguser` is a sample user for works with foreign server (and foreign tables).
303
307
304
308
### User mapping
305
309
306
310
There is no user or password conceptions in SQlite, hence `sqlite_fdw` no need any `CREATE USER MAPPING` command.
307
311
308
312
### 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
+
309
315
Please specify `table` option if SQLite table name is different from foreign table name.
310
316
311
317
```sql
312
318
CREATE FOREIGN TABLE t1 (
313
319
a integer,
314
-
b text)
320
+
b text
321
+
)
315
322
SERVER sqlite_server
316
323
OPTIONS (
317
324
table 't1_sqlite'
@@ -323,7 +330,8 @@ If you want to update tables, please add `OPTIONS (key 'true')` to a primary key
323
330
```sql
324
331
CREATE FOREIGN TABLE t1(
325
332
a integer OPTIONS (key 'true'),
326
-
b text)
333
+
b text
334
+
)
327
335
SERVER sqlite_server
328
336
OPTIONS (
329
337
table 't1_sqlite'
@@ -336,7 +344,8 @@ If you need to convert INT SQLite column (epoch Unix Time) to be treated/visuali
336
344
CREATE FOREIGN TABLE t1(
337
345
a integer,
338
346
b text,
339
-
c timestamp without time zone OPTIONS (column_type 'INT'))
347
+
c timestamp without time zone OPTIONS (column_type 'INT')
348
+
)
340
349
SERVER sqlite_server
341
350
OPTIONS (
342
351
table 't1_sqlite'
@@ -350,6 +359,7 @@ As above, but with aliased column names:
350
359
a integer,
351
360
b text OPTIONS (column_name 'test_id'),
352
361
c timestamp without time zone OPTIONS (column_type 'INT', column_name 'unixtime')
362
+
)
353
363
SERVER sqlite_server
354
364
OPTIONS (
355
365
table 't1_sqlite'
@@ -360,8 +370,8 @@ As above, but with aliased column names:
360
370
361
371
```sql
362
372
IMPORT FOREIGN SCHEMA someschema
363
-
FROM SERVER sqlite_server;
364
-
INTO public;
373
+
FROM SERVER sqlite_server
374
+
INTO public;
365
375
```
366
376
367
377
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
370
380
For the table from previous examples
371
381
372
382
```sql
373
-
SELECT*
374
-
FROM t1;
383
+
SELECT*FROM t1;
375
384
```
376
385
377
386
Limitations
378
387
-----------
379
388
389
+
### SQL commands
380
390
-`COPY` command for foreign tables is not supported
381
391
-`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.
383
393
-`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.
384
394
-`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)
386
402
- 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.
387
403
- 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.
388
404
- 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
394
410
Contributing
395
411
------------
396
412
397
-
## Contributing
398
413
Opening issues and pull requests on GitHub are welcome.
0 commit comments