forked from engobi/redis_fdw
-
Notifications
You must be signed in to change notification settings - Fork 2
/
redis_fdw.out
1400 lines (1250 loc) · 37.1 KB
/
redis_fdw.out
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
CREATE OR REPLACE FUNCTION atsort( a text[])
RETURNS text[]
LANGUAGE sql
IMMUTABLE STRICT
AS $function$
select array(select unnest($1) order by 1)
$function$
;
create server localredis foreign data wrapper redis_fdw;
create user mapping for public server localredis;
-- tables for all 5 data types (4 structured plus scalar)
create foreign table db15(key text, value text)
server localredis
options (database '15');
create foreign table db15_hash(key text, value text)
server localredis
options (database '15', tabletype 'hash');
create foreign table db15_set(key text, value text)
server localredis
options (database '15', tabletype 'set');
create foreign table db15_list(key text, value text)
server localredis
options (database '15', tabletype 'list');
create foreign table db15_zset(key text, value text)
server localredis
options (database '15', tabletype 'zset');
-- make sure they are all empty - if any are not stop the script right now
\set ON_ERROR_STOP
do $$
declare
rows bigint;
begin
select into rows
(select count(*) from db15) +
(select count(*) from db15_hash) +
(select count(*) from db15_set) +
(select count(*) from db15_list) +
(select count(*) from db15_zset);
if rows > 0
then
raise EXCEPTION 'db 15 not empty';
end if;
end;
$$;
\unset ON_ERROR_STOP
-- ok, empty, so now run the setup script
\! redis-cli < test/sql/redis_setup
OK
OK
OK
8
5
6
4
OK
OK
6
6
2
2
2
2
select * from db15 order by key;
key | value
-----+--------
baz | blurfl
foo | bar
(2 rows)
select * from db15 where key = 'foo';
key | value
-----+-------
foo | bar
(1 row)
-- hash
create foreign table db15_hash_prefix(key text, value text)
server localredis
options (tabletype 'hash', tablekeyprefix 'hash', database '15');
create foreign table db15_hash_prefix_array(key text, value text[])
server localredis
options (tabletype 'hash', tablekeyprefix 'hash', database '15');
create foreign table db15_hash_keyset_array(key text, value text[])
server localredis
options (tabletype 'hash', tablekeyset 'hkeys', database '15');
select * from db15_hash_prefix order by key;
key | value
-------+-------------------------------------------
hash1 | {"k1","v1","k2","v2","k3","v3","k4","v4"}
hash2 | {"k1","v5","k2","v6","k3","v7","k4","v8"}
(2 rows)
select * from db15_hash_prefix where key = 'hash1';
key | value
-------+-------------------------------------------
hash1 | {"k1","v1","k2","v2","k3","v3","k4","v4"}
(1 row)
select * from db15_hash_prefix_array order by key;
key | value
-------+---------------------------
hash1 | {k1,v1,k2,v2,k3,v3,k4,v4}
hash2 | {k1,v5,k2,v6,k3,v7,k4,v8}
(2 rows)
select * from db15_hash_prefix_array where key = 'hash1';
key | value
-------+---------------------------
hash1 | {k1,v1,k2,v2,k3,v3,k4,v4}
(1 row)
select * from db15_hash_keyset_array order by key;
key | value
-------+---------------------------
hash1 | {k1,v1,k2,v2,k3,v3,k4,v4}
hash2 | {k1,v5,k2,v6,k3,v7,k4,v8}
(2 rows)
select * from db15_hash_keyset_array where key = 'hash1';
key | value
-------+---------------------------
hash1 | {k1,v1,k2,v2,k3,v3,k4,v4}
(1 row)
-- a couple of nifty things we an do with hash tables
select key, hstore(value) from db15_hash_prefix_array order by key;
key | hstore
-------+------------------------------------------------
hash1 | "k1"=>"v1", "k2"=>"v2", "k3"=>"v3", "k4"=>"v4"
hash2 | "k1"=>"v5", "k2"=>"v6", "k3"=>"v7", "k4"=>"v8"
(2 rows)
create type atab as (k1 text, k2 text, k3 text);
select key, (populate_record(null::atab, hstore(value))).*
from db15_hash_prefix_array
order by key;
key | k1 | k2 | k3
-------+----+----+----
hash1 | v1 | v2 | v3
hash2 | v5 | v6 | v7
(2 rows)
-- set
create foreign table db15_set_prefix(key text, value text)
server localredis
options (tabletype 'set', tablekeyprefix 'set', database '15');
create foreign table db15_set_prefix_array(key text, value text[])
server localredis
options (tabletype 'set', tablekeyprefix 'set', database '15');
create foreign table db15_set_keyset_array(key text, value text[])
server localredis
options (tabletype 'set', tablekeyset 'skeys', database '15');
-- need to use atsort() on set results to get predicable output
-- since redis will give them back in arbitrary order
-- means we can't show the actual value for db15_set_prefix which has it as a
-- single text field
select key, atsort(value::text[]) as value from db15_set_prefix order by key;
key | value
------+---------------------------
set1 | {m1,m2,m3,m4,m5,m6,m7,m8}
set2 | {m10,m11,m12,m8,m9}
(2 rows)
select key, atsort(value::text[]) as value from db15_set_prefix where key = 'set1';
key | value
------+---------------------------
set1 | {m1,m2,m3,m4,m5,m6,m7,m8}
(1 row)
select key, atsort(value) as value from db15_set_prefix_array order by key;
key | value
------+---------------------------
set1 | {m1,m2,m3,m4,m5,m6,m7,m8}
set2 | {m10,m11,m12,m8,m9}
(2 rows)
select key, atsort(value) as value from db15_set_prefix_array where key = 'set1';
key | value
------+---------------------------
set1 | {m1,m2,m3,m4,m5,m6,m7,m8}
(1 row)
select key, atsort(value) as value from db15_set_keyset_array order by key;
key | value
------+---------------------------
set1 | {m1,m2,m3,m4,m5,m6,m7,m8}
set2 | {m10,m11,m12,m8,m9}
(2 rows)
select key, atsort(value) as value from db15_set_keyset_array where key = 'set1';
key | value
------+---------------------------
set1 | {m1,m2,m3,m4,m5,m6,m7,m8}
(1 row)
-- list
create foreign table db15_list_prefix(key text, value text)
server localredis
options (tabletype 'list', tablekeyprefix 'list', database '15');
create foreign table db15_list_prefix_array(key text, value text[])
server localredis
options (tabletype 'list', tablekeyprefix 'list', database '15');
create foreign table db15_list_keyset_array(key text, value text[])
server localredis
options (tabletype 'list', tablekeyset 'lkeys', database '15');
select * from db15_list_prefix order by key;
key | value
-------+---------------------------------
list1 | {"e6","e5","e4","e3","e2","e1"}
list2 | {"e10","e9","e8","e7"}
(2 rows)
select * from db15_list_prefix where key = 'list1';
key | value
-------+---------------------------------
list1 | {"e6","e5","e4","e3","e2","e1"}
(1 row)
select * from db15_list_prefix_array order by key;
key | value
-------+---------------------
list1 | {e6,e5,e4,e3,e2,e1}
list2 | {e10,e9,e8,e7}
(2 rows)
select * from db15_list_prefix_array where key = 'list1';
key | value
-------+---------------------
list1 | {e6,e5,e4,e3,e2,e1}
(1 row)
select * from db15_list_keyset_array order by key;
key | value
-------+---------------------
list1 | {e6,e5,e4,e3,e2,e1}
list2 | {e10,e9,e8,e7}
(2 rows)
select * from db15_list_keyset_array where key = 'list1';
key | value
-------+---------------------
list1 | {e6,e5,e4,e3,e2,e1}
(1 row)
-- zset
create foreign table db15_zset_prefix(key text, value text)
server localredis
options (tabletype 'zset', tablekeyprefix 'zset', database '15');
create foreign table db15_zset_prefix_array(key text, value text[])
server localredis
options (tabletype 'zset', tablekeyprefix 'zset', database '15');
create foreign table db15_zset_keyset_array(key text, value text[])
server localredis
options (tabletype 'zset', tablekeyset 'zkeys', database '15');
select * from db15_zset_prefix order by key;
key | value
-------+------------------------------------
zset1 | {"z1","z2","z3","z4","z5","z6"}
zset2 | {"z7","z8","z9","z10","z11","z12"}
(2 rows)
select * from db15_zset_prefix where key = 'zset1';
key | value
-------+---------------------------------
zset1 | {"z1","z2","z3","z4","z5","z6"}
(1 row)
select * from db15_zset_prefix_array order by key;
key | value
-------+------------------------
zset1 | {z1,z2,z3,z4,z5,z6}
zset2 | {z7,z8,z9,z10,z11,z12}
(2 rows)
select * from db15_zset_prefix_array where key = 'zset1';
key | value
-------+---------------------
zset1 | {z1,z2,z3,z4,z5,z6}
(1 row)
select * from db15_zset_keyset_array order by key;
key | value
-------+------------------------
zset1 | {z1,z2,z3,z4,z5,z6}
zset2 | {z7,z8,z9,z10,z11,z12}
(2 rows)
select * from db15_zset_keyset_array where key = 'zset1';
key | value
-------+---------------------
zset1 | {z1,z2,z3,z4,z5,z6}
(1 row)
-- singleton scalar
create foreign table db15_1key(value text)
server localredis
options (singleton_key 'foo', database '15');
select * from db15_1key;
value
-------
bar
(1 row)
-- singleton hash
create foreign table db15_1key_hash(key text, value text)
server localredis
options (tabletype 'hash', singleton_key 'hash1', database '15');
select * from db15_1key_hash order by key;
key | value
-----+-------
k1 | v1
k2 | v2
k3 | v3
k4 | v4
(4 rows)
-- singleton set
create foreign table db15_1key_set(value text)
server localredis
options (tabletype 'set', singleton_key 'set1', database '15');
select * from db15_1key_set order by value;
value
-------
m1
m2
m3
m4
m5
m6
m7
m8
(8 rows)
-- singleton list
create foreign table db15_1key_list(value text)
server localredis
options (tabletype 'list', singleton_key 'list1', database '15');
select * from db15_1key_list order by value;
value
-------
e1
e2
e3
e4
e5
e6
(6 rows)
-- singleton zset
create foreign table db15_1key_zset(value text)
server localredis
options (tabletype 'zset', singleton_key 'zset1', database '15');
select * from db15_1key_zset order by value;
value
-------
z1
z2
z3
z4
z5
z6
(6 rows)
-- singleton zset with scores
create foreign table db15_1key_zset_scores(value text, score numeric)
server localredis
options (tabletype 'zset', singleton_key 'zset1', database '15');
select * from db15_1key_zset_scores order by score desc;
value | score
-------+-------
z6 | 6
z5 | 5
z4 | 4
z3 | 3
z2 | 2
z1 | 1
(6 rows)
-- insert delete update
-- first clean the database again
\! redis-cli < test/sql/redis_clean
OK
OK
-- singleton scalar table
create foreign table db15_w_1key_scalar(val text)
server localredis
options (singleton_key 'w_1key_scalar', database '15');
select * from db15_w_1key_scalar;
val
-----
(0 rows)
insert into db15_w_1key_scalar values ('only row');
select * from db15_w_1key_scalar;
val
----------
only row
(1 row)
insert into db15_w_1key_scalar values ('only row');
ERROR: key already exists: w_1key_scalar
delete from db15_w_1key_scalar where val = 'not only row';
select * from db15_w_1key_scalar;
val
----------
only row
(1 row)
update db15_w_1key_scalar set val = 'new scalar val';
select * from db15_w_1key_scalar;
val
----------------
new scalar val
(1 row)
delete from db15_w_1key_scalar;
select * from db15_w_1key_scalar;
val
-----
(0 rows)
-- singleton hash
create foreign table db15_w_1key_hash(key text, val text)
server localredis
options (singleton_key 'w_1key_hash', tabletype 'hash', database '15');
select * from db15_w_1key_hash;
key | val
-----+-----
(0 rows)
insert into db15_w_1key_hash values ('a','b'), ('c','d'),('e','f');
select * from db15_w_1key_hash order by key;
key | val
-----+-----
a | b
c | d
e | f
(3 rows)
insert into db15_w_1key_hash values ('a','b');
ERROR: key already exists: a
delete from db15_w_1key_hash where key = 'a';
delete from db15_w_1key_hash where key = 'a';
select * from db15_w_1key_hash order by key;
key | val
-----+-----
c | d
e | f
(2 rows)
update db15_w_1key_hash set key = 'x', val = 'y' where key = 'c';
select * from db15_w_1key_hash order by key;
key | val
-----+-----
e | f
x | y
(2 rows)
update db15_w_1key_hash set val = 'z' where key = 'e';
select * from db15_w_1key_hash order by key;
key | val
-----+-----
e | z
x | y
(2 rows)
update db15_w_1key_hash set key = 'w' where key = 'e';
select * from db15_w_1key_hash order by key;
key | val
-----+-----
w | z
x | y
(2 rows)
-- singleton list
create foreign table db15_w_1key_list(val text)
server localredis
options (singleton_key 'w_1key_list', tabletype 'list', database '15');
select * from db15_w_1key_list;
val
-----
(0 rows)
insert into db15_w_1key_list values ('a'), ('c'),('e');
-- for lists the order should (must) be determinate
select * from db15_w_1key_list /* order by val */ ;
val
-----
a
c
e
(3 rows)
delete from db15_w_1key_list where val = 'a';
ERROR: delete not supported for this type of table
delete from db15_w_1key_list where val = 'z';
ERROR: delete not supported for this type of table
insert into db15_w_1key_list values ('b'), ('d'),('f'),('a'); -- dups allowed here
select * from db15_w_1key_list /* order by val */;
val
-----
a
c
e
b
d
f
a
(7 rows)
update db15_w_1key_list set val = 'y';
ERROR: update not supported for this type of table
-- singleton set
create foreign table db15_w_1key_set(key text)
server localredis
options (singleton_key 'w_1key_set', tabletype 'set', database '15');
select * from db15_w_1key_set;
key
-----
(0 rows)
insert into db15_w_1key_set values ('a'), ('c'),('e');
select * from db15_w_1key_set order by key;
key
-----
a
c
e
(3 rows)
insert into db15_w_1key_set values ('a'); -- error - dup
ERROR: key already exists: a
delete from db15_w_1key_set where key = 'c';
select * from db15_w_1key_set order by key;
key
-----
a
e
(2 rows)
update db15_w_1key_set set key = 'x' where key = 'e';
select * from db15_w_1key_set order by key;
key
-----
a
x
(2 rows)
-- singleton zset with scores
create foreign table db15_w_1key_zset(key text, priority numeric)
server localredis
options (singleton_key 'w_1key_zset', tabletype 'zset', database '15');
select * from db15_w_1key_zset;
key | priority
-----+----------
(0 rows)
insert into db15_w_1key_zset values ('a',1), ('c',5),('e',-5), ('h',10);
select * from db15_w_1key_zset order by priority;
key | priority
-----+----------
e | -5
a | 1
c | 5
h | 10
(4 rows)
insert into db15_w_1key_zset values ('a',99);
ERROR: key already exists: a
delete from db15_w_1key_zset where key = 'a';
select * from db15_w_1key_zset order by priority;
key | priority
-----+----------
e | -5
c | 5
h | 10
(3 rows)
delete from db15_w_1key_zset where priority = '5';
select * from db15_w_1key_zset order by priority;
key | priority
-----+----------
e | -5
h | 10
(2 rows)
update db15_w_1key_zset set key = 'x', priority = 99 where priority = '-5';
select * from db15_w_1key_zset order by priority;
key | priority
-----+----------
h | 10
x | 99
(2 rows)
update db15_w_1key_zset set key = 'y' where key = 'h';
select * from db15_w_1key_zset order by priority;
key | priority
-----+----------
y | 10
x | 99
(2 rows)
update db15_w_1key_zset set priority = 20 where key = 'y';
select * from db15_w_1key_zset order by priority;
key | priority
-----+----------
y | 20
x | 99
(2 rows)
-- singleton zset no scores
-- use set from last step
delete from db15_w_1key_zset;
insert into db15_w_1key_zset values ('e',-5);
create foreign table db15_w_1key_zsetx(key text)
server localredis
options (singleton_key 'w_1key_zset', tabletype 'zset', database '15');
select * from db15_w_1key_zsetx;
key
-----
e
(1 row)
insert into db15_w_1key_zsetx values ('a'), ('c'),('e'); -- can't insert
ERROR: operation not supported for singleton zset table without priorities column
update db15_w_1key_zsetx set key = 'z' where key = 'e';
select * from db15_w_1key_zsetx order by key;
key
-----
z
(1 row)
delete from db15_w_1key_zsetx where key = 'z';
select * from db15_w_1key_zsetx order by key;
key
-----
(0 rows)
-- non-singleton scalar table no prefix no keyset
create foreign table db15_w_scalar(key text, val text)
server localredis
options (database '15');
select * from db15_w_scalar;
key | val
-----+-----
(0 rows)
insert into db15_w_scalar values ('a_ws','b'), ('c_ws','d'),('e_ws','f');
select * from db15_w_scalar order by key;
key | val
------+-----
a_ws | b
c_ws | d
e_ws | f
(3 rows)
delete from db15_w_scalar where key = 'a_ws';
select * from db15_w_scalar order by key;
key | val
------+-----
c_ws | d
e_ws | f
(2 rows)
update db15_w_scalar set key = 'x_ws', val='y' where key = 'e_ws';
select * from db15_w_scalar order by key;
key | val
------+-----
c_ws | d
x_ws | y
(2 rows)
update db15_w_scalar set key = 'z_ws' where key = 'c_ws';
select * from db15_w_scalar order by key;
key | val
------+-----
x_ws | y
z_ws | d
(2 rows)
update db15_w_scalar set val = 'z' where key = 'z_ws';
select * from db15_w_scalar order by key;
key | val
------+-----
x_ws | y
z_ws | z
(2 rows)
/*
-- don't delete the whole namespace
delete from db15_w_scalar;
select * from db15_w_scalar;
*/
-- non-singleton scalar table keyprefix
create foreign table db15_w_scalar_pfx(key text, val text)
server localredis
options (database '15', tablekeyprefix 'w_scalar_');
select * from db15_w_scalar_pfx;
key | val
-----+-----
(0 rows)
insert into db15_w_scalar_pfx values ('w_scalar_a','b'), ('w_scalar_c','d'),('w_scalar_e','f');
insert into db15_w_scalar_pfx values ('x','y'); -- prefix error
ERROR: key 'x' does not match table key prefix 'w_scalar_'
insert into db15_w_scalar_pfx values ('w_scalar_a','x'); -- dup error
ERROR: key already exists: w_scalar_a
select * from db15_w_scalar_pfx order by key;
key | val
------------+-----
w_scalar_a | b
w_scalar_c | d
w_scalar_e | f
(3 rows)
delete from db15_w_scalar_pfx where key = 'w_scalar_a';
select * from db15_w_scalar_pfx order by key;
key | val
------------+-----
w_scalar_c | d
w_scalar_e | f
(2 rows)
update db15_w_scalar_pfx set key = 'x', val = 'y' where key = 'w_scalar_c'; -- prefix err
ERROR: key prefix condition violation: x
update db15_w_scalar_pfx set key = 'x' where key = 'w_scalar_c'; -- prefix err
ERROR: key prefix condition violation: x
update db15_w_scalar_pfx set key = 'w_scalar_x', val = 'y' where key = 'w_scalar_c';
select * from db15_w_scalar_pfx order by key;
key | val
------------+-----
w_scalar_e | f
w_scalar_x | y
(2 rows)
update db15_w_scalar_pfx set key = 'w_scalar_z' where key = 'w_scalar_x';
select * from db15_w_scalar_pfx order by key;
key | val
------------+-----
w_scalar_e | f
w_scalar_z | y
(2 rows)
update db15_w_scalar_pfx set val = 'w' where key = 'w_scalar_e';
select * from db15_w_scalar_pfx order by key;
key | val
------------+-----
w_scalar_e | w
w_scalar_z | y
(2 rows)
delete from db15_w_scalar_pfx;
select * from db15_w_scalar_pfx order by key;
key | val
-----+-----
(0 rows)
-- non-singleton scalar table keyset
create foreign table db15_w_scalar_kset(key text, val text)
server localredis
options (database '15', tablekeyset 'w_scalar_kset');
select * from db15_w_scalar_kset order by key;
key | val
-----+-----
(0 rows)
insert into db15_w_scalar_kset values ('a_wsks','b'), ('c_wsks','d'),('e_wsks','f');
insert into db15_w_scalar_kset values ('a_wsks','x'); -- dup error
ERROR: key already exists: a_wsks
select * from db15_w_scalar_kset order by key;
key | val
--------+-----
a_wsks | b
c_wsks | d
e_wsks | f
(3 rows)
delete from db15_w_scalar_kset where key = 'a_wsks';
select * from db15_w_scalar_kset order by key;
key | val
--------+-----
c_wsks | d
e_wsks | f
(2 rows)
update db15_w_scalar_kset set key = 'x_wsks', val = 'y' where key = 'c_wsks';
select * from db15_w_scalar_kset order by key;
key | val
--------+-----
e_wsks | f
x_wsks | y
(2 rows)
update db15_w_scalar_kset set key = 'z_wsks' where key = 'x_wsks';
select * from db15_w_scalar_kset order by key;
key | val
--------+-----
e_wsks | f
z_wsks | y
(2 rows)
update db15_w_scalar_kset set val = 'w' where key = 'e_wsks';
select * from db15_w_scalar_kset order by key;
key | val
--------+-----
e_wsks | w
z_wsks | y
(2 rows)
delete from db15_w_scalar_kset;
select * from db15_w_scalar_kset order by key;
key | val
-----+-----
(0 rows)
-- non-singleton set table no prefix no keyset
-- non-array case -- fails
create foreign table db15_w_set_nonarr(key text, val text)
server localredis
options (database '15', tabletype 'set');
insert into db15_w_set_nonarr values ('nkseta','{b,c,d}'), ('nksetc','{d,e,f}'),('nksete','{f,g,h}');
ERROR: cannot insert into this type of Redis table - needs an array
/*
-- namespace too polluted for this case
create foreign table db15_w_set(key text, val text[])
server localredis
options (database '15', tabletype 'set');
select * from db15_w_set;
insert into db15_w_set values ('nkseta','{b,c,d}'), ('nksetc','{d,e,f}'),('nksete','{f,g,h}');
select * from db15_w_set;
delete from db15_w_set where key = 'nkseta';
select * from db15_w_set;
delete from db15_w_set;
select * from db15_w_set;
*/
-- non-singleton set table keyprefix
create foreign table db15_w_set_pfx(key text, val text[])
server localredis
options (database '15', tabletype 'set', tablekeyprefix 'w_set_');
select * from db15_w_set_pfx;
key | val
-----+-----
(0 rows)
insert into db15_w_set_pfx values ('w_set_a','{b,c,d}'), ('w_set_c','{d,e,f}'),('w_set_e','{f,g,h}');
insert into db15_w_set_pfx values ('x','{y}'); -- prefix error
ERROR: key 'x' does not match table key prefix 'w_set_'
insert into db15_w_set_pfx values ('w_set_a','{x,y,z}'); -- dup error
ERROR: key already exists: w_set_a
select key, atsort(val) as val from db15_w_set_pfx order by key;
key | val
---------+---------
w_set_a | {b,c,d}
w_set_c | {d,e,f}
w_set_e | {f,g,h}
(3 rows)
delete from db15_w_set_pfx where key = 'w_set_a';
select key, atsort(val) as val from db15_w_set_pfx order by key;
key | val
---------+---------
w_set_c | {d,e,f}
w_set_e | {f,g,h}
(2 rows)
update db15_w_set_pfx set key = 'x' where key = 'w_set_c'; -- prefix err
ERROR: key prefix condition violation: x
update db15_w_set_pfx set key = 'x', val = '{y}' where key = 'w_set_c'; -- prefix err
ERROR: key prefix condition violation: x
update db15_w_set_pfx set key = 'w_set_x', val = '{x,y,z}' where key = 'w_set_c';
select key, atsort(val) as val from db15_w_set_pfx order by key;
key | val
---------+---------
w_set_e | {f,g,h}
w_set_x | {x,y,z}
(2 rows)
update db15_w_set_pfx set key = 'w_set_z' where key = 'w_set_x';
select key, atsort(val) as val from db15_w_set_pfx order by key;
key | val
---------+---------
w_set_e | {f,g,h}
w_set_z | {x,y,z}
(2 rows)
update db15_w_set_pfx set val = '{q,r,s}' where key = 'w_set_e';
select key, atsort(val) as val from db15_w_set_pfx order by key;
key | val
---------+---------
w_set_e | {q,r,s}
w_set_z | {x,y,z}
(2 rows)
delete from db15_w_set_pfx;
select key, atsort(val) as val from db15_w_set_pfx order by key;
key | val
-----+-----
(0 rows)
-- non-singleton set table keyset
create foreign table db15_w_set_kset(key text, val text[])
server localredis
options (database '15', tabletype 'set', tablekeyset 'w_set_kset');
select * from db15_w_set_kset;
key | val
-----+-----
(0 rows)
insert into db15_w_set_kset values ('a_wsk','{b,c,d}'), ('c_wsk','{d,e,f}'),('e_wsk','{f,g,h}');
insert into db15_w_set_kset values ('a_wsk','{x}'); -- dup error
ERROR: key already exists: a_wsk
select key, atsort(val) as val from db15_w_set_kset order by key;
key | val
-------+---------
a_wsk | {b,c,d}
c_wsk | {d,e,f}
e_wsk | {f,g,h}
(3 rows)
delete from db15_w_set_kset where key = 'a_wsk';
select key, atsort(val) as val from db15_w_set_kset order by key;
key | val
-------+---------
c_wsk | {d,e,f}
e_wsk | {f,g,h}
(2 rows)
update db15_w_set_kset set key = 'x_wsk', val = '{x,y,z}' where key = 'c_wsk';
select key, atsort(val) as val from db15_w_set_kset order by key;
key | val
-------+---------
e_wsk | {f,g,h}
x_wsk | {x,y,z}
(2 rows)
update db15_w_set_kset set key = 'z_wsk' where key = 'x_wsk';
select key, atsort(val) as val from db15_w_set_kset order by key;
key | val
-------+---------
e_wsk | {f,g,h}
z_wsk | {x,y,z}
(2 rows)
update db15_w_set_kset set val = '{q,r,s}' where key = 'e_wsk';
select key, atsort(val) as val from db15_w_set_kset order by key;
key | val
-------+---------
e_wsk | {q,r,s}
z_wsk | {x,y,z}
(2 rows)
delete from db15_w_set_kset;
select * from db15_w_set_kset;
key | val
-----+-----
(0 rows)
-- non-singleton list table keyprefix
create foreign table db15_w_list_pfx(key text, val text[])
server localredis
options (database '15', tabletype 'list', tablekeyprefix 'w_list_');
select * from db15_w_list_pfx;
key | val
-----+-----
(0 rows)
insert into db15_w_list_pfx values ('w_list_a','{b,c,d}'), ('w_list_c','{d,e,f}'),('w_list_e','{f,g,h}');
insert into db15_w_list_pfx values ('x','{y}'); -- prefix error
ERROR: key 'x' does not match table key prefix 'w_list_'
insert into db15_w_list_pfx values ('w_list_a','{x,y,z}'); -- dup error
ERROR: key already exists: w_list_a
select * from db15_w_list_pfx order by key;
key | val
----------+---------
w_list_a | {b,c,d}
w_list_c | {d,e,f}
w_list_e | {f,g,h}
(3 rows)
delete from db15_w_list_pfx where key = 'w_list_a';
select * from db15_w_list_pfx order by key;
key | val
----------+---------
w_list_c | {d,e,f}
w_list_e | {f,g,h}
(2 rows)
update db15_w_list_pfx set key = 'x' where key = 'w_list_c'; -- prefix err
ERROR: key prefix condition violation: x
update db15_w_list_pfx set key = 'x', val = '{y}' where key = 'w_list_c'; -- prefix err
ERROR: key prefix condition violation: x