Skip to content

Commit ab94985

Browse files
committed
Rename add_api to add_updatable_views for clarity
1 parent 8561b0d commit ab94985

20 files changed

+130
-98
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,10 @@ The test suite uses `pg_regress` and is designed to be fully idempotent, creatin
326326
- `drop_foreign_key_by_name(table_oid regclass, key_name name) RETURNS boolean`: Drops any type of foreign key by its unique generated or user-provided name.
327327

328328
### Updatable Views (for PostgREST and `FOR PORTION OF` emulation)
329-
The `add_api` function creates views to simplify interaction with temporal tables. This includes a view that only shows the *current* state of data (ideal for PostgREST) and a view that emulates the `FOR PORTION OF` syntax for updating historical records.
329+
The `add_updatable_views` function creates views to simplify interaction with temporal tables. This includes a view that only shows the *current* state of data (ideal for PostgREST) and a view that emulates the `FOR PORTION OF` syntax for updating historical records.
330330

331-
- `add_api(table_oid regclass DEFAULT NULL, era_name name DEFAULT 'valid') RETURNS boolean`
332-
- `drop_api(table_oid regclass, era_name name, drop_behavior sql_saga.drop_behavior DEFAULT 'RESTRICT', cleanup boolean DEFAULT false) RETURNS boolean`
331+
- `add_updatable_views(table_oid regclass DEFAULT NULL, era_name name DEFAULT 'valid') RETURNS boolean`
332+
- `drop_updatable_views(table_oid regclass, era_name name, drop_behavior sql_saga.drop_behavior DEFAULT 'RESTRICT', cleanup boolean DEFAULT false) RETURNS boolean`
333333

334334
### High-Performance Bulk Data Loading (`temporal_merge`)
335335
- `temporal_merge(p_target_table regclass, p_source_table regclass, p_id_columns TEXT[], p_ephemeral_columns TEXT[], p_mode sql_saga.temporal_merge_mode DEFAULT 'upsert_patch', p_era_name name DEFAULT 'valid', p_source_row_id_column name DEFAULT 'row_id', p_founding_id_column name DEFAULT NULL, p_update_source_with_assigned_entity_ids BOOLEAN DEFAULT false)`: A powerful, set-based procedure for performing `INSERT`, `UPDATE`, and `DELETE` operations on temporal tables from a source table. It is designed to solve complex data loading scenarios (e.g., idempotent imports, data corrections) in a single, efficient, and transactionally-safe statement.

expected/05_excluded_columns.out

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ SELECT sql_saga.add_era('gen_cols_test', '"from"', '"until"', 'p');
5050
t
5151
(1 row)
5252

53-
SELECT sql_saga.add_api('gen_cols_test', 'p');
54-
add_api
55-
---------
53+
SELECT sql_saga.add_updatable_views('gen_cols_test', 'p');
54+
add_updatable_views
55+
---------------------
5656
t
5757
(1 row)
5858

@@ -78,9 +78,9 @@ TABLE gen_cols_test ORDER BY """from""";
7878
(2 rows)
7979

8080
-- Clean up
81-
SELECT sql_saga.drop_api('gen_cols_test', 'p');
82-
drop_api
83-
----------
81+
SELECT sql_saga.drop_updatable_views('gen_cols_test', 'p');
82+
drop_updatable_views
83+
----------------------
8484
t
8585
(1 row)
8686

expected/07_for_portion_of.out

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ SELECT sql_saga.add_era('pricing', 'quantity_from', 'quantity_until', 'quantitie
4242
t
4343
(1 row)
4444

45-
SELECT sql_saga.add_api('pricing', 'quantities');
46-
add_api
47-
---------
45+
SELECT sql_saga.add_updatable_views('pricing', 'quantities');
46+
add_updatable_views
47+
---------------------
4848
t
4949
(1 row)
5050

@@ -126,9 +126,9 @@ SELECT sql_saga.add_era('pricing', 'quantity_from', 'quantity_until', 'quantitie
126126
t
127127
(1 row)
128128

129-
SELECT sql_saga.add_api('pricing', 'quantities');
130-
add_api
131-
---------
129+
SELECT sql_saga.add_updatable_views('pricing', 'quantities');
130+
add_updatable_views
131+
---------------------
132132
t
133133
(1 row)
134134

@@ -141,9 +141,9 @@ ERROR: cannot drop table pricing because other objects depend on it
141141
DETAIL: view pricing__for_portion_of_quantities depends on table pricing
142142
HINT: Use DROP ... CASCADE to drop the dependent objects too.
143143
ROLLBACK TO SAVEPOINT expect_fail;
144-
SELECT sql_saga.drop_api('pricing', NULL);
145-
drop_api
146-
----------
144+
SELECT sql_saga.drop_updatable_views('pricing', NULL);
145+
drop_updatable_views
146+
----------------------
147147
t
148148
(1 row)
149149

@@ -174,9 +174,9 @@ SELECT sql_saga.add_era('bt', 'valid_from', 'valid_until', 'p');
174174
t
175175
(1 row)
176176

177-
SELECT sql_saga.add_api('bt', 'p');
178-
add_api
179-
---------
177+
SELECT sql_saga.add_updatable_views('bt', 'p');
178+
add_updatable_views
179+
---------------------
180180
t
181181
(1 row)
182182

@@ -196,9 +196,9 @@ TABLE bt ORDER BY valid_from, valid_until;
196196
3 | (0,0) | sample | 31 | 41
197197
(3 rows)
198198

199-
SELECT sql_saga.drop_api('bt', 'p');
200-
drop_api
201-
----------
199+
SELECT sql_saga.drop_updatable_views('bt', 'p');
200+
drop_updatable_views
201+
----------------------
202202
t
203203
(1 row)
204204

@@ -228,7 +228,7 @@ DROP EXTENSION IF EXISTS btree_gist CASCADE;
228228
-- This is necessary before the role can be dropped.
229229
DROP OWNED BY sql_saga_unprivileged_user;
230230
DROP ROLE IF EXISTS sql_saga_unprivileged_user;
231-
-- Test that add_api works without a PK, using a temporal unique key instead.
231+
-- Test that add_updatable_views works without a PK, using a temporal unique key instead.
232232
\i sql/include/test_setup.sql
233233
--
234234
-- test_setup.sql
@@ -274,9 +274,9 @@ SELECT sql_saga.add_unique_key('no_pk_test', ARRAY['id']);
274274
no_pk_test_id_valid
275275
(1 row)
276276

277-
SELECT sql_saga.add_api('no_pk_test');
278-
add_api
279-
---------
277+
SELECT sql_saga.add_updatable_views('no_pk_test');
278+
add_updatable_views
279+
---------------------
280280
t
281281
(1 row)
282282

@@ -296,9 +296,9 @@ TABLE no_pk_test ORDER BY valid_from;
296296
1 | initial | 2020-09-01 | 2021-01-01
297297
(3 rows)
298298

299-
SELECT sql_saga.drop_api('no_pk_test', 'valid');
300-
drop_api
301-
----------
299+
SELECT sql_saga.drop_updatable_views('no_pk_test', 'valid');
300+
drop_updatable_views
301+
----------------------
302302
t
303303
(1 row)
304304

expected/09_drop_protection.out

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ CONTEXT: PL/pgSQL function sql_saga.drop_protection() line 93 at RAISE
6161
ROLLBACK TO SAVEPOINT s3;
6262
/* api */
6363
ALTER TABLE dp ADD CONSTRAINT dp_pkey PRIMARY KEY (id);
64-
SELECT sql_saga.add_api('dp', 'p');
65-
add_api
66-
---------
64+
SELECT sql_saga.add_updatable_views('dp', 'p');
65+
add_updatable_views
66+
---------------------
6767
t
6868
(1 row)
6969

7070
SAVEPOINT s4;
7171
DROP VIEW dp__for_portion_of_p;
72-
ERROR: cannot drop view "public.dp__for_portion_of_p", call "sql_saga.drop_api()" instead
72+
ERROR: cannot drop view "public.dp__for_portion_of_p", call "sql_saga.drop_updatable_views()" instead
7373
CONTEXT: PL/pgSQL function sql_saga.drop_protection() line 173 at RAISE
7474
ROLLBACK TO SAVEPOINT s4;
7575
SAVEPOINT s5;
@@ -82,9 +82,9 @@ ALTER TABLE dp DROP CONSTRAINT dp_pkey;
8282
ERROR: cannot drop primary key on table "dp" because it has a FOR PORTION OF view for period "p"
8383
CONTEXT: PL/pgSQL function sql_saga.drop_protection() line 197 at RAISE
8484
ROLLBACK TO SAVEPOINT s6;
85-
SELECT sql_saga.drop_api('dp', 'p');
86-
drop_api
87-
----------
85+
SELECT sql_saga.drop_updatable_views('dp', 'p');
86+
drop_updatable_views
87+
----------------------
8888
t
8989
(1 row)
9090

expected/10_rename_following.out

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ TABLE sql_saga.era;
7979

8080
/* api */
8181
ALTER TABLE rename_test ADD COLUMN id integer PRIMARY KEY;
82-
SELECT sql_saga.add_api('rename_test', 'p');
83-
add_api
84-
---------
82+
SELECT sql_saga.add_updatable_views('rename_test', 'p');
83+
add_updatable_views
84+
---------------------
8585
t
8686
(1 row)
8787

@@ -98,9 +98,9 @@ TABLE sql_saga.api_view;
9898
public | rename_test | p | public | rename_test__for_portion_of_p | portion_trigger
9999
(1 row)
100100

101-
SELECT sql_saga.drop_api('rename_test', 'p');
102-
drop_api
103-
----------
101+
SELECT sql_saga.drop_updatable_views('rename_test', 'p');
102+
drop_updatable_views
103+
----------------------
104104
t
105105
(1 row)
106106

expected/12_acl.out

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ SELECT sql_saga.add_era('owner_test', 'f', 'u', 'p');
5555
t
5656
(1 row)
5757

58-
SELECT sql_saga.add_api('owner_test', 'p');
59-
add_api
60-
---------
58+
SELECT sql_saga.add_updatable_views('owner_test', 'p');
59+
add_updatable_views
60+
---------------------
6161
t
6262
(1 row)
6363

@@ -77,9 +77,9 @@ TABLE show_owners ORDER BY object_name;
7777
public | owner_test__for_portion_of_p | view | periods_acl_2
7878
(2 rows)
7979

80-
SELECT sql_saga.drop_api('owner_test', 'p');
81-
drop_api
82-
----------
80+
SELECT sql_saga.drop_updatable_views('owner_test', 'p');
81+
drop_updatable_views
82+
----------------------
8383
t
8484
(1 row)
8585

@@ -118,9 +118,9 @@ SELECT sql_saga.add_era('fpacl', 'f', 'u', 'p');
118118
t
119119
(1 row)
120120

121-
SELECT sql_saga.add_api('fpacl', 'p');
122-
add_api
123-
---------
121+
SELECT sql_saga.add_updatable_views('fpacl', 'p');
122+
add_updatable_views
123+
---------------------
124124
t
125125
(1 row)
126126

@@ -201,9 +201,9 @@ TABLE show_acls ORDER BY sort_order;
201201
18 | public | fpacl__for_portion_of_p | view | periods_acl_2 | SELECT
202202
(18 rows)
203203

204-
SELECT sql_saga.drop_api('fpacl', 'p');
205-
drop_api
206-
----------
204+
SELECT sql_saga.drop_updatable_views('fpacl', 'p');
205+
drop_updatable_views
206+
----------------------
207207
t
208208
(1 row)
209209

expected/21_api_lifecycle.out

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,20 @@ TABLE sql_saga.foreign_keys;
145145
rooms_house_id_valid | temporal_to_temporal | public | rooms | {house_id} | valid | {id,house_id,valid_from,valid_until} | houses_id_valid | SIMPLE | NO ACTION | NO ACTION | rooms_house_id_valid_fk_insert | rooms_house_id_valid_fk_update | | | rooms_house_id_valid_uk_update | rooms_house_id_valid_uk_delete
146146
(1 row)
147147

148+
-- Add API views
149+
SELECT sql_saga.add_updatable_views('houses');
150+
add_updatable_views
151+
---------------------
152+
t
153+
(1 row)
154+
155+
TABLE sql_saga.api_view;
156+
table_schema | table_name | era_name | view_schema_name | view_table_name | trigger_name
157+
--------------+------------+----------+------------------+------------------------------+----------------------
158+
public | houses | valid | public | houses__for_portion_of_valid | for_portion_of_valid
159+
(1 row)
160+
161+
\d houses_valid_v
148162
-- While sql_saga is active
149163
\d rooms
150164
Table "public.rooms"
@@ -198,6 +212,17 @@ Check constraints:
198212
"shifts_valid_check" CHECK (valid_from < valid_until)
199213

200214
-- Remove sql_saga
215+
SELECT sql_saga.drop_updatable_views('houses', 'valid');
216+
drop_updatable_views
217+
----------------------
218+
t
219+
(1 row)
220+
221+
TABLE sql_saga.api_view;
222+
table_schema | table_name | era_name | view_schema_name | view_table_name | trigger_name
223+
--------------+------------+----------+------------------+-----------------+--------------
224+
(0 rows)
225+
201226
SELECT sql_saga.drop_foreign_key('rooms', ARRAY['house_id'], 'valid');
202227
drop_foreign_key
203228
------------------

expected/43_benchmark_performance.out

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
-------------------------------------------+-----------+-----------------+----------------+------------+-----------------
33
BEGIN | 0 | 0 secs | | 0 rows | ~0 rows/s
44
Constraints enabled | 0 | 0 secs | 0 secs | 0 rows | ~0 rows/s
5-
Era INSERTs delayed constraints | 10000 | 0 secs | 0 secs | 10000 rows | ~24200 rows/s
6-
Era INSERTs | 10000 | 1 secs | 1 secs | 10000 rows | ~19200 rows/s
5+
Era INSERTs delayed constraints | 10000 | 0 secs | 0 secs | 10000 rows | ~23200 rows/s
6+
Era INSERTs | 10000 | 1 secs | 1 secs | 10000 rows | ~19000 rows/s
77
Era Update deferred constraints | 10000 | 9 secs | 8 secs | 10000 rows | ~1200 rows/s
8-
Era Update non-key | 10000 | 9 secs | 0 secs | 10000 rows | ~74400 rows/s
9-
Temporal Merge SEED | 16000 | 46 secs | 37 secs | 16000 rows | ~400 rows/s
10-
Temporal Merge 20% INSERT 80% PATCH | 20000 | 115 secs | 69 secs | 20000 rows | ~300 rows/s
11-
History Only Benchmark | 0 | 115 secs | 0 secs | 0 rows | ~0 rows/s
12-
History INSERTs | 10000 | 116 secs | 0 secs | 10000 rows | ~51200 rows/s
13-
History Update | 10000 | 116 secs | 0 secs | 10000 rows | ~49600 rows/s
14-
Era + History Benchmark | 0 | 116 secs | 0 secs | 0 rows | ~0 rows/s
15-
Era + History INSERTs | 10000 | 117 secs | 1 secs | 10000 rows | ~12600 rows/s
16-
Era + History Update deferred constraints | 10000 | 124 secs | 7 secs | 10000 rows | ~1500 rows/s
17-
Era + History Update non-key | 10000 | 124 secs | 1 secs | 10000 rows | ~11400 rows/s
18-
Constraints disabled | 0 | 125 secs | 0 secs | 0 rows | ~0 rows/s
19-
Tear down complete | 0 | 125 secs | 0 secs | 0 rows | ~0 rows/s
8+
Era Update non-key | 10000 | 9 secs | 0 secs | 10000 rows | ~74100 rows/s
9+
Temporal Merge SEED | 16000 | 45 secs | 36 secs | 16000 rows | ~400 rows/s
10+
Temporal Merge 20% INSERT 80% PATCH | 20000 | 106 secs | 60 secs | 20000 rows | ~300 rows/s
11+
History Only Benchmark | 0 | 106 secs | 0 secs | 0 rows | ~0 rows/s
12+
History INSERTs | 10000 | 106 secs | 0 secs | 10000 rows | ~48000 rows/s
13+
History Update | 10000 | 106 secs | 0 secs | 10000 rows | ~47300 rows/s
14+
Era + History Benchmark | 0 | 106 secs | 0 secs | 0 rows | ~0 rows/s
15+
Era + History INSERTs | 10000 | 107 secs | 1 secs | 10000 rows | ~16800 rows/s
16+
Era + History Update deferred constraints | 10000 | 111 secs | 5 secs | 10000 rows | ~2100 rows/s
17+
Era + History Update non-key | 10000 | 112 secs | 1 secs | 10000 rows | ~13700 rows/s
18+
Constraints disabled | 0 | 112 secs | 0 secs | 0 rows | ~0 rows/s
19+
Tear down complete | 0 | 112 secs | 0 secs | 0 rows | ~0 rows/s
2020
(17 rows)
2121

sql/05_excluded_columns.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ CREATE TABLE gen_cols_test (
2525

2626
-- Add sql_saga features with non-standard, quoted column names
2727
SELECT sql_saga.add_era('gen_cols_test', '"from"', '"until"', 'p');
28-
SELECT sql_saga.add_api('gen_cols_test', 'p');
28+
SELECT sql_saga.add_updatable_views('gen_cols_test', 'p');
2929

3030
-- Insert initial data
3131
INSERT INTO gen_cols_test (product, """from""", """until""", price) VALUES ('Widget', 10, 20, 100);
@@ -42,7 +42,7 @@ UPDATE gen_cols_test__for_portion_of_p SET """from""" = 15, """until""" = 20, pr
4242
TABLE gen_cols_test ORDER BY """from""";
4343

4444
-- Clean up
45-
SELECT sql_saga.drop_api('gen_cols_test', 'p');
45+
SELECT sql_saga.drop_updatable_views('gen_cols_test', 'p');
4646
SELECT sql_saga.drop_era('gen_cols_test', 'p');
4747
DROP TABLE gen_cols_test;
4848

0 commit comments

Comments
 (0)