Skip to content

Commit

Permalink
Add out of range checks for PostgreSQL int and smallint columns
Browse files Browse the repository at this point in the history
  • Loading branch information
mkgrgis committed Dec 28, 2023
1 parent a387b2f commit eb992da
Show file tree
Hide file tree
Showing 12 changed files with 274 additions and 17 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,19 +167,19 @@ SQLite `NULL` affinity always can be transparent converted for a nullable column
- **database** as *string*, **required**, no default

SQLite database path.

- **updatable** as *boolean*, optional, default *true*

This option allow or disallow write operations on SQLite database file.

- **truncatable** as *boolean*, optional, default *true*

Allows foreign tables to be truncated using the `TRUNCATE` command.

- **keep_connections** as *boolean*, optional, default *true*

Allows to keep connections to SQLite while there is no SQL operations between PostgreSQL and SQLite.

- **batch_size** as *integer*, optional, default *1*

Specifies the number of rows which should be inserted in a single `INSERT` operation. This setting can be overridden for individual tables.
Expand All @@ -203,17 +203,17 @@ In OS `sqlite_fdw` works as executed code with permissions of user of PostgreSQL
SQLite table name. Use if not equal to name of foreign table in PostgreSQL. Also see about [identifier case handling](#identifier-case-handling).

- **truncatable** as *boolean*, optional, default from the same `CREATE SERVER` option

See `CREATE SERVER` options section for details.

- **batch_size** as *integer*, optional, default from the same `CREATE SERVER` option

See `CREATE SERVER` options section for details.

- **updatable** as *boolean*, optional, default *true*

This option can allow or disallow write operations on a SQLite table independed of the same server option.

`sqlite_fdw` accepts the following column-level options via the
`CREATE FOREIGN TABLE` command:

Expand All @@ -225,7 +225,7 @@ In OS `sqlite_fdw` works as executed code with permissions of user of PostgreSQL

Set preferred SQLite affinity for some PostgreSQL data types can be stored in different ways
in SQLite (mixed affinity case). Updated and inserted values will have this affinity. Default preferred SQLite affinity for `timestamp` and `uuid` PostgreSQL data types is `text`.

- Use `INT` value for SQLite column (epoch Unix Time) to be treated/visualized as `timestamp` in PostgreSQL.
- Use `BLOB` value for SQLite column to be treated/visualized as `uuid` in PostgreSQL 14+.

Expand Down Expand Up @@ -327,7 +327,7 @@ with names composed from ASCII base latin letters *only*.
CREATE TABLE T_dia (
"Ä" INTEGER,
"ä" NUMERIC
);
);
```

For SQLite there is no difference between
Expand All @@ -340,7 +340,7 @@ For SQLite there is no difference between
```
For PostgreSQL the query with comment `№4` is independend query to table `T`, not to table `t` as other queries.
Please note this table name composed from ASCII base latin letters *only*. This is not applicable for other
alphabet systems or mixed names. This is because `toLower` operation in PostgreSQL is Unicode opration but
alphabet systems or mixed names. This is because `toLower` operation in PostgreSQL is Unicode opration but
ASCII only operation in SQLite, hence other characters will not be changed.

```sql
Expand Down
24 changes: 24 additions & 0 deletions expected/12.16/extra/int4.out
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,30 @@ ERROR: function lcm(integer, integer) does not exist
LINE 1: SELECT lcm(f1, f2) FROM INT4_TMP;
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
--Testcase 135:
DELETE FROM INT4_TMP;
--Testcase 136:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int8;
--Testcase 137:
INSERT INTO INT4_TMP VALUES (x'7FFFFFFF'::int8 + 1, 0);
--Testcase 138:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int4;
--Testcase 139:
SELECT * FROM INT4_TMP; -- overflow
ERROR: Out of range for data type "integer"
HINT: Value 2147483648 in column "f1"
--Testcase 140:
DELETE FROM INT4_TMP;
--Testcase 141:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int8;
--Testcase 142:
INSERT INTO INT4_TMP VALUES (-(x'7FFFFFFF'::int8) - 2, 0);
--Testcase 143:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int4;
--Testcase 144:
SELECT * FROM INT4_TMP; -- overflow
ERROR: Out of range for data type "integer"
HINT: Value -2147483649 in column "f1"
-- Clean up
DO $d$
declare
Expand Down
24 changes: 24 additions & 0 deletions expected/13.12/extra/int4.out
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,30 @@ INSERT INTO INT4_TMP VALUES (2147483647::int4, 2147483646::int4);
--Testcase 134:
SELECT lcm(f1, f2) FROM INT4_TMP; -- overflow
ERROR: integer out of range
--Testcase 135:
DELETE FROM INT4_TMP;
--Testcase 136:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int8;
--Testcase 137:
INSERT INTO INT4_TMP VALUES (x'7FFFFFFF'::int8 + 1, 0);
--Testcase 138:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int4;
--Testcase 139:
SELECT * FROM INT4_TMP; -- overflow
ERROR: Out of range for data type "integer"
HINT: Value 2147483648 in column "f1"
--Testcase 140:
DELETE FROM INT4_TMP;
--Testcase 141:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int8;
--Testcase 142:
INSERT INTO INT4_TMP VALUES (-(x'7FFFFFFF'::int8) - 2, 0);
--Testcase 143:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int4;
--Testcase 144:
SELECT * FROM INT4_TMP; -- overflow
ERROR: Out of range for data type "integer"
HINT: Value -2147483649 in column "f1"
-- Clean up
DO $d$
declare
Expand Down
24 changes: 24 additions & 0 deletions expected/14.9/extra/int4.out
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,30 @@ INSERT INTO INT4_TMP VALUES (2147483647::int4, 2147483646::int4);
--Testcase 134:
SELECT lcm(f1, f2) FROM INT4_TMP; -- overflow
ERROR: integer out of range
--Testcase 135:
DELETE FROM INT4_TMP;
--Testcase 136:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int8;
--Testcase 137:
INSERT INTO INT4_TMP VALUES (x'7FFFFFFF'::int8 + 1, 0);
--Testcase 138:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int4;
--Testcase 139:
SELECT * FROM INT4_TMP; -- overflow
ERROR: Out of range for data type "integer"
HINT: Value 2147483648 in column "f1"
--Testcase 140:
DELETE FROM INT4_TMP;
--Testcase 141:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int8;
--Testcase 142:
INSERT INTO INT4_TMP VALUES (-(x'7FFFFFFF'::int8) - 2, 0);
--Testcase 143:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int4;
--Testcase 144:
SELECT * FROM INT4_TMP; -- overflow
ERROR: Out of range for data type "integer"
HINT: Value -2147483649 in column "f1"
-- Clean up
DO $d$
declare
Expand Down
24 changes: 24 additions & 0 deletions expected/15.4/extra/int4.out
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,30 @@ INSERT INTO INT4_TMP VALUES (2147483647::int4, 2147483646::int4);
--Testcase 134:
SELECT lcm(f1, f2) FROM INT4_TMP; -- overflow
ERROR: integer out of range
--Testcase 135:
DELETE FROM INT4_TMP;
--Testcase 136:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int8;
--Testcase 137:
INSERT INTO INT4_TMP VALUES (x'7FFFFFFF'::int8 + 1, 0);
--Testcase 138:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int4;
--Testcase 139:
SELECT * FROM INT4_TMP; -- overflow
ERROR: Out of range for data type "integer"
HINT: Value 2147483648 in column "f1"
--Testcase 140:
DELETE FROM INT4_TMP;
--Testcase 141:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int8;
--Testcase 142:
INSERT INTO INT4_TMP VALUES (-(x'7FFFFFFF'::int8) - 2, 0);
--Testcase 143:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int4;
--Testcase 144:
SELECT * FROM INT4_TMP; -- overflow
ERROR: Out of range for data type "integer"
HINT: Value -2147483649 in column "f1"
-- Clean up
DO $d$
declare
Expand Down
24 changes: 24 additions & 0 deletions expected/16.0/extra/int4.out
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,30 @@ SELECT f1 FROM special_case_int4;
----
(0 rows)

--Testcase 135:
DELETE FROM INT4_TMP;
--Testcase 136:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int8;
--Testcase 137:
INSERT INTO INT4_TMP VALUES (x'7FFFFFFF'::int8 + 1, 0);
--Testcase 138:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int4;
--Testcase 139:
SELECT * FROM INT4_TMP; -- overflow
ERROR: Out of range for data type "integer"
HINT: Value 2147483648 in column "f1"
--Testcase 140:
DELETE FROM INT4_TMP;
--Testcase 141:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int8;
--Testcase 142:
INSERT INTO INT4_TMP VALUES (-(x'7FFFFFFF'::int8) - 2, 0);
--Testcase 143:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int4;
--Testcase 144:
SELECT * FROM INT4_TMP; -- overflow
ERROR: Out of range for data type "integer"
HINT: Value -2147483649 in column "f1"
-- Clean up
DO $d$
declare
Expand Down
22 changes: 22 additions & 0 deletions sql/12.16/extra/int4.sql
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,28 @@ INSERT INTO INT4_TMP VALUES (2147483647::int4, 2147483646::int4);
--Testcase 134:
SELECT lcm(f1, f2) FROM INT4_TMP; -- overflow

--Testcase 135:
DELETE FROM INT4_TMP;
--Testcase 136:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int8;
--Testcase 137:
INSERT INTO INT4_TMP VALUES (x'7FFFFFFF'::int8 + 1, 0);
--Testcase 138:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int4;
--Testcase 139:
SELECT * FROM INT4_TMP; -- overflow

--Testcase 140:
DELETE FROM INT4_TMP;
--Testcase 141:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int8;
--Testcase 142:
INSERT INTO INT4_TMP VALUES (-(x'7FFFFFFF'::int8) - 2, 0);
--Testcase 143:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int4;
--Testcase 144:
SELECT * FROM INT4_TMP; -- overflow

-- Clean up
DO $d$
declare
Expand Down
22 changes: 22 additions & 0 deletions sql/13.12/extra/int4.sql
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,28 @@ INSERT INTO INT4_TMP VALUES (2147483647::int4, 2147483646::int4);
--Testcase 134:
SELECT lcm(f1, f2) FROM INT4_TMP; -- overflow

--Testcase 135:
DELETE FROM INT4_TMP;
--Testcase 136:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int8;
--Testcase 137:
INSERT INTO INT4_TMP VALUES (x'7FFFFFFF'::int8 + 1, 0);
--Testcase 138:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int4;
--Testcase 139:
SELECT * FROM INT4_TMP; -- overflow

--Testcase 140:
DELETE FROM INT4_TMP;
--Testcase 141:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int8;
--Testcase 142:
INSERT INTO INT4_TMP VALUES (-(x'7FFFFFFF'::int8) - 2, 0);
--Testcase 143:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int4;
--Testcase 144:
SELECT * FROM INT4_TMP; -- overflow

-- Clean up
DO $d$
declare
Expand Down
22 changes: 22 additions & 0 deletions sql/14.9/extra/int4.sql
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,28 @@ INSERT INTO INT4_TMP VALUES (2147483647::int4, 2147483646::int4);
--Testcase 134:
SELECT lcm(f1, f2) FROM INT4_TMP; -- overflow

--Testcase 135:
DELETE FROM INT4_TMP;
--Testcase 136:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int8;
--Testcase 137:
INSERT INTO INT4_TMP VALUES (x'7FFFFFFF'::int8 + 1, 0);
--Testcase 138:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int4;
--Testcase 139:
SELECT * FROM INT4_TMP; -- overflow

--Testcase 140:
DELETE FROM INT4_TMP;
--Testcase 141:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int8;
--Testcase 142:
INSERT INTO INT4_TMP VALUES (-(x'7FFFFFFF'::int8) - 2, 0);
--Testcase 143:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int4;
--Testcase 144:
SELECT * FROM INT4_TMP; -- overflow

-- Clean up
DO $d$
declare
Expand Down
22 changes: 22 additions & 0 deletions sql/15.4/extra/int4.sql
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,28 @@ INSERT INTO INT4_TMP VALUES (2147483647::int4, 2147483646::int4);
--Testcase 134:
SELECT lcm(f1, f2) FROM INT4_TMP; -- overflow

--Testcase 135:
DELETE FROM INT4_TMP;
--Testcase 136:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int8;
--Testcase 137:
INSERT INTO INT4_TMP VALUES (x'7FFFFFFF'::int8 + 1, 0);
--Testcase 138:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int4;
--Testcase 139:
SELECT * FROM INT4_TMP; -- overflow

--Testcase 140:
DELETE FROM INT4_TMP;
--Testcase 141:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int8;
--Testcase 142:
INSERT INTO INT4_TMP VALUES (-(x'7FFFFFFF'::int8) - 2, 0);
--Testcase 143:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int4;
--Testcase 144:
SELECT * FROM INT4_TMP; -- overflow

-- Clean up
DO $d$
declare
Expand Down
22 changes: 22 additions & 0 deletions sql/16.0/extra/int4.sql
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,28 @@ DELETE FROM special_case_int4;
INSERT INTO special_case_int4 VALUES ('100__000'::int4);
SELECT f1 FROM special_case_int4;

--Testcase 135:
DELETE FROM INT4_TMP;
--Testcase 136:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int8;
--Testcase 137:
INSERT INTO INT4_TMP VALUES (x'7FFFFFFF'::int8 + 1, 0);
--Testcase 138:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int4;
--Testcase 139:
SELECT * FROM INT4_TMP; -- overflow

--Testcase 140:
DELETE FROM INT4_TMP;
--Testcase 141:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int8;
--Testcase 142:
INSERT INTO INT4_TMP VALUES (-(x'7FFFFFFF'::int8) - 2, 0);
--Testcase 143:
ALTER FOREIGN TABLE INT4_TMP ALTER COLUMN f1 TYPE int4;
--Testcase 144:
SELECT * FROM INT4_TMP; -- overflow

-- Clean up
DO $d$
declare
Expand Down
Loading

0 comments on commit eb992da

Please sign in to comment.