Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial RETURNING implementation #107

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ GISTEST=nogis
endif

ifndef REGRESS
REGRESS = extra/sqlite_fdw_post types/bitstring types/bool types/float4 types/float8 types/int4 types/int8 types/numeric types/$(GISTEST) types/macaddr types/macaddr8 types/out_of_range types/timestamp types/uuid extra/join extra/limit extra/aggregates extra/prepare extra/select_having extra/select extra/insert extra/update extra/encodings sqlite_fdw type_$(GISTEST) aggregate selectfunc
REGRESS = extra/sqlite_fdw_post types/bitstring types/bool types/float4 types/float8 types/int4 types/int8 types/numeric types/$(GISTEST) types/macaddr types/macaddr8 types/out_of_range types/timestamp types/uuid extra/join extra/limit extra/aggregates extra/prepare extra/select_having extra/select extra/insert extra/update extra/encodings sqlite_fdw type_$(GISTEST) aggregate selectfunc extra/returning
endif

REGRESS_OPTS = --encoding=utf8
Expand Down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ Features
### Common features
- Transactions
- Support `INSERT`/`UPDATE`/`DELETE` (both Direct modification and Foreign modification), see [access control](#connection-to-sqlite-database-file-and-access-control) about conditions of succesfully data modification.
- Support `RETURNING` for `INSERT`/`UPDATE`/`DELETE`.
- Support `TRUNCATE` by deparsing into `DELETE` statement without `WHERE` clause.
- Allow control over whether foreign servers keep connections open after transaction completion. This is controlled by `keep_connections` and defaults to on.
- Support list cached connections to foreign servers by using function `sqlite_fdw_get_connections()`
- Support discard cached connections to foreign servers by using function `sqlite_fdw_disconnect()`, `sqlite_fdw_disconnect_all()`.
- Support Bulk `INSERT` by using `batch_size` option
- Support `INSERT`/`UPDATE` with generated column
- Support `ON CONFLICT DO NOTHING`
- Support `INSERT` ... `ON CONFLICT DO NOTHING`
- Support `WITH CHECK OPTION` views after a foreign table
- Support mixed SQLite [data affinity](https://www.sqlite.org/datatype3.html) input and filtering (`SELECT`/`WHERE` usage) for such data types as
- `timestamp`: `text` and `int`,
- `uuid`: `text`(32..39) and `blob`(16),
Expand All @@ -59,7 +61,8 @@ Features

### Pushing down
- `WHERE` clauses are pushdowned
- Aggregate function are pushdowned
- `RETURNING` clauses are pushdowned
- Some aggregate functions are pushdowned
- `ORDER BY` is pushdowned
- Joins (left/right/inner/cross/semi) are pushdowned
- `CASE` expressions are pushdowned.
Expand Down Expand Up @@ -700,6 +703,13 @@ funct_name (type arg ...)
}
}
```

To debug, you need to build PostgreSQL in debug mode. Use the following options.
```bash
./configure --prefix=<path_to_postgresql_build_folder> --enable-cassert --enable-debug CFLAGS="-ggdb -O0 -g3 -fno-omit-frame-pointer"
```
Also please refer https://wiki.postgresql.org/wiki/Developer_FAQ#What_debugging_features_are_available.3F

Useful links
------------

Expand Down
13 changes: 7 additions & 6 deletions connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ sqlite_get_connection(ForeignServer *server, bool truncatable)
}

/*
* sqlite_open_db
* Open remote sqlite database using specified database path
* and flags of opened file descriptor mode.
*/
Expand Down Expand Up @@ -230,7 +231,7 @@ sqlite_make_new_connection(ConnCacheEntry *entry, ForeignServer *server)
{
const char *dbpath = NULL;
ListCell *lc;
int flags = 0;
int flags = 0;

Assert(entry->conn == NULL);

Expand Down Expand Up @@ -389,8 +390,8 @@ sqlite_begin_remote_xact(ConnCacheEntry *entry)
}
}


/*
* sqlitefdw_report_error
* Report an sqlite execution error
*/
void
Expand All @@ -400,7 +401,7 @@ sqlitefdw_report_error(int elevel, sqlite3_stmt * stmt, sqlite3 * conn,
const char *message = sqlite3_errmsg(conn);
int sqlstate = ERRCODE_FDW_ERROR;

/* copy sql before callling another SQLite API */
/* copy sql before calling another SQLite API */
if (message)
message = pstrdup(message);

Expand All @@ -418,9 +419,9 @@ sqlitefdw_report_error(int elevel, sqlite3_stmt * stmt, sqlite3 * conn,
));
}


/*
* sqlitefdw_xact_callback --- cleanup at main-transaction end.
* sqlitefdw_xact_callback
* cleanup at main-transaction end.
*/
static void
sqlitefdw_xact_callback(XactEvent event, void *arg)
Expand Down Expand Up @@ -1038,7 +1039,7 @@ sqlite_cache_stmt(ForeignServer *server, sqlite3_stmt * *stmt)
}

/*
* finalize all sqlite statement
* finalize all SQLite statement
*/
static void
sqlite_finalize_list_stmt(List **list)
Expand Down
Loading
Loading