File: coltap.sql

package info (click to toggle)
pgtap 1.3.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,792 kB
  • sloc: sql: 25,795; sh: 790; makefile: 287; perl: 175
file content (759 lines) | stat: -rw-r--r-- 21,224 bytes parent folder | download | duplicates (2)
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
\unset ECHO
\i test/setup.sql
-- \i sql/pgtap.sql

SELECT plan(276);
-- SELECT * from no_plan();

CREATE TYPE public."myType" AS (
    id INT,
    foo INT
);

CREATE SCHEMA hidden;
CREATE TYPE hidden.stuff AS (
    id INT,
    foo INT
);

-- This will be rolled back. :-)
SET client_min_messages = warning;
CREATE TABLE public.sometab(
    id      INT NOT NULL PRIMARY KEY,
    name    TEXT DEFAULT '',
    numb    NUMERIC(10, 2) DEFAULT NULL,
    "myNum" NUMERIC(8) DEFAULT 24,
    myat    TIMESTAMP DEFAULT NOW(),
    cuser   TEXT DEFAULT CURRENT_USER,
    suser   TEXT DEFAULT SESSION_USER,
    auser   TEXT DEFAULT USER,
    crole   TEXT DEFAULT CURRENT_ROLE,
    csch    TEXT DEFAULT CURRENT_SCHEMA,
    ccat    TEXT DEFAULT CURRENT_CATALOG,
    cdate   DATE DEFAULT CURRENT_DATE,
    ctime   TIMETZ DEFAULT CURRENT_TIME,
    ctstz   TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
    ltime   TIME DEFAULT LOCALTIME,
    ltstz   TIMESTAMPTZ DEFAULT LOCALTIMESTAMP,
    plain   INTEGER,
    camel   "myType",
    inval   INTERVAL(0),
    isecd   INTERVAL SECOND(0),
    iyear   INTERVAL YEAR,
    stuff   hidden.stuff
);

CREATE OR REPLACE FUNCTION fakeout( eok boolean, name text )
RETURNS SETOF TEXT AS $$
DECLARE
    descr text := coalesce( name || ' ', 'Test ' ) || 'should ';
BEGIN
    RETURN NEXT pass(descr || CASE eok WHEN true then 'pass' ELSE 'fail' END);
    RETURN NEXT pass(descr || 'have the proper description');
    RETURN NEXT pass(descr || 'have the proper diagnostics');
    RETURN;
END;
$$ LANGUAGE PLPGSQL;

RESET client_min_messages;

/****************************************************************************/
-- Test col_not_null().
SELECT * FROM check_test(
    col_not_null( 'pg_catalog', 'pg_type', 'typname', 'typname not null' ),
    true,
    'col_not_null( sch, tab, col, desc )',
    'typname not null',
    ''
);
SELECT * FROM check_test(
    col_not_null( 'pg_catalog', 'pg_type', 'typname'::name ),
    true,
    'col_not_null( sch, tab, col::name )',
    'Column pg_catalog.pg_type.typname should be NOT NULL',
    ''
);

SELECT * FROM check_test(
    col_not_null( 'sometab', 'id', 'blah blah blah' ),
    true,
    'col_not_null( tab, col, desc )',
    'blah blah blah',
    ''
);

SELECT * FROM check_test(
    col_not_null( 'sometab', 'id' ),
    true,
    'col_not_null( table, column )',
    'Column sometab.id should be NOT NULL',
    ''
);

-- Make sure failure is correct.
SELECT * FROM check_test(
    col_not_null( 'sometab', 'name' ),
    false,
    'col_not_null( table, column ) fail',
    'Column sometab.name should be NOT NULL',
    ''
);

-- Make sure nonexisting column is correct
SELECT * FROM check_test(
    col_not_null( 'pg_catalog', 'pg_type', 'foo', 'desc' ),
    false,
    'col_not_null( sch, tab, noncol, desc )',
    'desc',
    '    Column pg_catalog.pg_type.foo does not exist'
);

SELECT * FROM check_test(
    col_not_null( 'sometab', 'foo' ),
    false,
    'col_not_null( table, noncolumn ) fail',
    'Column sometab.foo should be NOT NULL',
    '    Column sometab.foo does not exist'
);

/****************************************************************************/
-- Test col_is_null().
SELECT * FROM check_test(
    col_is_null( 'public', 'sometab', 'name', 'name is null' ),
    true,
    'col_is_null( sch, tab, col, desc )',
    'name is null',
    ''
);

SELECT * FROM check_test(
    col_is_null( 'public', 'sometab', 'name'::name ),
    true,
    'col_is_null( sch, tab, col::name )',
    'Column public.sometab.name should allow NULL',
    ''
);

SELECT * FROM check_test(
    col_is_null( 'sometab', 'name', 'my desc' ),
    true,
    'col_is_null( tab, col, desc )',
    'my desc',
    ''
);

SELECT * FROM check_test(
    col_is_null( 'sometab', 'name' ),
    true,
    'col_is_null( tab, col )',
    'Column sometab.name should allow NULL',
    ''
);
-- Make sure failure is correct.
SELECT * FROM check_test(
    col_is_null( 'sometab', 'id' ),
    false,
    'col_is_null( tab, col ) fail',
    'Column sometab.id should allow NULL',
    ''
);

-- Make sure nonexisting column is correct
SELECT * FROM check_test(
    col_is_null( 'pg_catalog', 'pg_type', 'foo', 'desc' ),
    false,
    'col_is_null( sch, tab, noncol, desc )',
    'desc',
    '    Column pg_catalog.pg_type.foo does not exist'
);

SELECT * FROM check_test(
    col_is_null( 'sometab', 'foo' ),
    false,
    'col_is_null( table, noncolumn ) fail',
    'Column sometab.foo should allow NULL',
    '    Column sometab.foo does not exist'
);

/****************************************************************************/
-- Test col_type_is().
SELECT * FROM check_test(
    col_type_is( 'public', 'sometab', 'ctstz', 'pg_catalog', 'timestamptz', 'ctstz is tstz' ),
    true,
    'col_type_is( sch, tab, col, sch, type, desc )',
    'ctstz is tstz',
    ''
);

SELECT * FROM check_test(
    col_type_is( 'public', 'sometab', 'ctstz', 'pg_catalog'::name, 'timestamptz' ),
    true,
    'col_type_is( sch, tab, col, sch, type, desc )',
    'Column public.sometab.ctstz should be type pg_catalog.timestamptz',
    ''
);

-- Try case-sensitive column name.
SELECT * FROM check_test(
    col_type_is( 'public', 'sometab', 'myNum', 'pg_catalog', 'numeric(8,0)', 'myNum is numeric' ),
    true,
    'col_type_is( sch, tab, myNum, sch, type, desc )',
    'myNum is numeric',
    ''
);

SELECT * FROM check_test(
    col_type_is( 'public', 'sometab', 'myNum', 'pg_catalog'::name, 'numeric(8,0)' ),
    true,
    'col_type_is( sch, tab, myNum, sch, type, desc )',
    'Column public.sometab."myNum" should be type pg_catalog.numeric(8,0)',
    ''
);

-- Try case-sensitive type name.
SELECT * FROM check_test(
    col_type_is( 'public', 'sometab', 'camel', 'public', '"myType"', 'camel is myType' ),
    true,
    'col_type_is( sch, tab, camel, sch, type, desc )',
    'camel is myType',
    ''
);

SELECT * FROM check_test(
    col_type_is( 'public', 'sometab', 'camel', 'public'::name, '"myType"' ),
    true,
    'col_type_is( sch, tab, camel, sch, type )',
    'Column public.sometab.camel should be type public."myType"',
    ''
);

SELECT * FROM check_test(
    col_type_is( 'public', 'sometab', 'camel', '"myType"', 'whatever' ),
    true,
    'col_type_is( sch, tab, camel, type, desc )',
    'whatever',
    ''
);

-- Try interval.
SELECT * FROM check_test(
    col_type_is( 'public', 'sometab', 'inval', 'pg_catalog', 'interval(0)', 'inval is interval(0)' ),
    true,
    'col_type_is( sch, tab, interval, sch, type, desc )',
    'inval is interval(0)',
    ''
);

SELECT * FROM check_test(
    col_type_is( 'public', 'sometab', 'inval', 'pg_catalog'::name, 'interval(0)' ),
    true,
    'col_type_is( sch, tab, interval, sch, type, desc )',
    'Column public.sometab.inval should be type pg_catalog.interval(0)',
    ''
);

SELECT * FROM check_test(
    col_type_is( 'public', 'sometab', 'inval', 'interval(0)', 'whatever' ),
    true,
    'col_type_is( sch, tab, inval, type, desc )',
    'whatever',
    ''
);

-- Try interval second.
SELECT * FROM check_test(
    col_type_is( 'public', 'sometab', 'isecd', 'pg_catalog', 'interval second(0)', 'isecd is interval second(0)' ),
    true,
    'col_type_is( sch, tab, intsec, sch, type, desc )',
    'isecd is interval second(0)',
    ''
);

SELECT * FROM check_test(
    col_type_is( 'public', 'sometab', 'inval', 'pg_catalog'::name, 'interval(0)' ),
    true,
    'col_type_is( sch, tab, interval, sch, type, desc )',
    'Column public.sometab.inval should be type pg_catalog.interval(0)',
    ''
);

SELECT * FROM check_test(
    col_type_is( 'public', 'sometab', 'inval', 'interval(0)', 'whatever' ),
    true,
    'col_type_is( sch, tab, inval, type, desc )',
    'whatever',
    ''
);

-- Try type not in search path.
SELECT * FROM check_test(
    col_type_is( 'public', 'sometab', 'stuff', 'hidden', 'stuff', 'stuff is stuff' ),
    true,
    'col_type_is( sch, tab, stuff, sch, type, desc )',
    'stuff is stuff',
    ''
);

SELECT * FROM check_test(
    col_type_is( 'public', 'sometab', 'stuff', 'hidden'::name, 'stuff' ),
    true,
    'col_type_is( sch, tab, stuff, sch, type, desc )',
    'Column public.sometab.stuff should be type hidden.stuff',
    ''
);

-- Try failures.
SELECT * FROM check_test(
    col_type_is( 'public', 'sometab', 'name', 'pg_catalog', 'int', 'whatever' ),
    false,
    'col_type_is( sch, tab, col, sch, type, desc ) fail',
    'whatever',
    '        have: pg_catalog.text
        want: pg_catalog.integer'
);

SELECT * FROM check_test(
    col_type_is( 'public', 'sometab', 'name', 'pg_catalog', 'blech', 'whatever' ),
    false,
    'col_type_is( sch, tab, col, sch, non-type, desc )',
    'whatever',
    '    Type pg_catalog.blech does not exist'
);

SELECT * FROM check_test(
    col_type_is( 'public', 'sometab', 'name', 'fooey', 'text', 'whatever' ),
    false,
    'col_type_is( sch, tab, col, non-sch, type, desc )',
    'whatever',
    '    Type fooey.text does not exist'
);

SELECT * FROM check_test(
    col_type_is( 'public', 'sometab', 'name', 'fooey', 'text', 'whatever' ),
    false,
    'col_type_is( sch, tab, col, non-sch, type, desc )',
    'whatever',
    '    Type fooey.text does not exist'
);

SELECT * FROM check_test(
    col_type_is( 'public', 'sometab', 'name', 'nonesuch', 'whatever' ),
    false,
    'col_type_is( sch, tab, col, non-type, desc )',
    'whatever',
    '    Type nonesuch does not exist'
);

SELECT * FROM check_test(
    col_type_is( 'sometab', 'name', 'nonesuch', 'whatever' ),
    false,
    'col_type_is( tab, col, non-type, desc )',
    'whatever',
    '    Type nonesuch does not exist'
);

SELECT * FROM check_test(
    col_type_is( 'public', 'sometab', 'nonesuch', 'pg_catalog', 'text', 'whatever' ),
    false,
    'col_type_is( sch, tab, non-col, sch, type, desc )',
    'whatever',
    '   Column public.sometab.nonesuch does not exist'
);

SELECT * FROM check_test(
    col_type_is( 'public', 'sometab', 'name', 'text', 'name is text' ),
    true,
    'col_type_is( sch, tab, col, type, desc )',
    'name is text',
    ''
);

SELECT * FROM check_test(
    col_type_is( 'public', 'sometab', 'name'::name, 'text' ),
    true,
    'col_type_is( sch, tab, col, type )',
    'Column public.sometab.name should be type text',
    ''
);

SELECT * FROM check_test(
    col_type_is( 'sometab', 'name', 'text', 'yadda yadda yadda' ),
    true,
    'col_type_is( tab, col, type, desc )',
    'yadda yadda yadda',
    ''
);

SELECT * FROM check_test(
    col_type_is( 'sometab', 'name', 'text' ),
    true,
    'col_type_is( tab, col, type )',
    'Column sometab.name should be type text',
    ''
);

-- Make sure failure is correct.
SELECT * FROM check_test(
    col_type_is( 'sometab', 'name', 'int4' ),
    false,
    'col_type_is( tab, col, type ) fail',
    'Column sometab.name should be type int4',
    '        have: text
        want: integer'
);

-- Make sure missing column is in diagnostics.
SELECT * FROM check_test(
    col_type_is( 'sometab', 'blah', 'int4' ),
    false,
    'col_type_is( tab, noncol, type ) fail',
    'Column sometab.blah should be type int4',
    '   Column sometab.blah does not exist'
);

SELECT * FROM check_test(
    col_type_is( 'public', 'sometab', 'blah', 'text', 'blah is text' ),
    false,
    'col_type_is( sch, tab, noncol, type, desc ) fail',
    'blah is text',
    '   Column public.sometab.blah does not exist'
);

/****************************************************************************/
-- Try col_type_is() with precision.
SELECT * FROM check_test(
    col_type_is( 'public', 'sometab', 'numb', 'numeric(10,2)', 'lol' ),
    true,
    'col_type_is with precision',
    'lol',
    ''
);

-- Check its diagnostics.
SELECT * FROM check_test(
    col_type_is( 'sometab', 'myNum', 'numeric(7)', 'should be numeric(7)' ),
    false,
    'col_type_is precision fail',
    'should be numeric(7)',
    '        have: numeric(8,0)
        want: numeric(7,0)'
);

/****************************************************************************/
-- Test col_has_default().
SELECT * FROM check_test(
    col_has_default( 'public', 'sometab', 'name', 'desc' ),
    true,
    'col_has_default( sch, tab, col, desc )',
    'desc',
    ''
);
SELECT * FROM check_test(
    col_has_default( 'sometab', 'name', 'desc' ),
    true,
    'col_has_default( tab, col, desc )',
    'desc',
    ''
);
SELECT * FROM check_test(
    col_has_default( 'sometab', 'name' ),
    true,
    'col_has_default( tab, col )',
    'Column sometab.name should have a default',
    ''
);

-- Check with a column with no default.
SELECT * FROM check_test(
    col_has_default( 'public', 'sometab', 'plain', 'desc' ),
    false,
    'col_has_default( sch, tab, col, desc )',
    'desc',
    ''
);
SELECT * FROM check_test(
    col_has_default( 'sometab', 'plain', 'desc' ),
    false,
    'col_has_default( tab, col, desc )',
    'desc',
    ''
);
SELECT * FROM check_test(
    col_has_default( 'sometab', 'plain' ),
    false,
    'col_has_default( tab, col )',
    'Column sometab.plain should have a default',
    ''
);

-- Check with a nonexistent column.
SELECT * FROM check_test(
    col_has_default( 'public', 'sometab', '__asdfasdfs__', 'desc' ),
    false,
    'col_has_default( sch, tab, col, desc )',
    'desc',
    '    Column public.sometab.__asdfasdfs__ does not exist'
);
SELECT * FROM check_test(
    col_has_default( 'sometab', '__asdfasdfs__', 'desc' ),
    false,
    'col_has_default( tab, col, desc )',
    'desc',
    '    Column sometab.__asdfasdfs__ does not exist'
);
SELECT * FROM check_test(
    col_has_default( 'sometab', '__asdfasdfs__' ),
    false,
    'col_has_default( tab, col )',
    'Column sometab.__asdfasdfs__ should have a default',
    '    Column sometab.__asdfasdfs__ does not exist'
);

/****************************************************************************/
-- Test col_hasnt_default().
SELECT * FROM check_test(
    col_hasnt_default( 'public', 'sometab', 'name', 'desc' ),
    false,
    'col_hasnt_default( sch, tab, col, desc )',
    'desc',
    ''
);
SELECT * FROM check_test(
    col_hasnt_default( 'sometab', 'name', 'desc' ),
    false,
    'col_hasnt_default( tab, col, desc )',
    'desc',
    ''
);
SELECT * FROM check_test(
    col_hasnt_default( 'sometab', 'name' ),
    false,
    'col_hasnt_default( tab, col )',
    'Column sometab.name should not have a default',
    ''
);

-- Check with a column with no default.
SELECT * FROM check_test(
    col_hasnt_default( 'public', 'sometab', 'plain', 'desc' ),
    true,
    'col_hasnt_default( sch, tab, col, desc )',
    'desc',
    ''
);
SELECT * FROM check_test(
    col_hasnt_default( 'sometab', 'plain', 'desc' ),
    true,
    'col_hasnt_default( tab, col, desc )',
    'desc',
    ''
);
SELECT * FROM check_test(
    col_hasnt_default( 'sometab', 'plain' ),
    true,
    'col_hasnt_default( tab, col )',
    'Column sometab.plain should not have a default',
    ''
);

-- Check with a nonexistent column.
SELECT * FROM check_test(
    col_hasnt_default( 'public', 'sometab', '__asdfasdfs__', 'desc' ),
    false,
    'col_hasnt_default( sch, tab, col, desc )',
    'desc',
    '    Column public.sometab.__asdfasdfs__ does not exist'
);
SELECT * FROM check_test(
    col_hasnt_default( 'sometab', '__asdfasdfs__', 'desc' ),
    false,
    'col_hasnt_default( tab, col, desc )',
    'desc',
    '    Column sometab.__asdfasdfs__ does not exist'
);
SELECT * FROM check_test(
    col_hasnt_default( 'sometab', '__asdfasdfs__' ),
    false,
    'col_hasnt_default( tab, col )',
    'Column sometab.__asdfasdfs__ should not have a default',
    '    Column sometab.__asdfasdfs__ does not exist'
);

/****************************************************************************/
-- Test col_default_is().

SELECT * FROM check_test(
    col_default_is( 'public', 'sometab', 'name', ''::text, 'name should default to empty string' ),
    true,
    'col_default_is( sch, tab, col, def, desc )',
    'name should default to empty string',
    ''
);

SELECT * FROM check_test(
    col_default_is( 'public', 'sometab', 'name', 'foo'::text, 'name should default to ''foo''' ),
    false,
    'col_default_is() fail',
    'name should default to ''foo''',
    '        have: 
        want: foo'
);

SELECT * FROM check_test(
    col_default_is( 'sometab', 'name', ''::text, 'name should default to empty string' ),
    true,
    'col_default_is( tab, col, def, desc )',
    'name should default to empty string',
    ''
);

SELECT * FROM check_test(
    col_default_is( 'sometab', 'name', ''::text ),
    true,
    'col_default_is( tab, col, def )',
    'Column sometab.name should default to ''''',
    ''
);

-- Make sure it works with a NULL default.
SELECT * FROM check_test(
    col_default_is( 'sometab', 'myNum', 24 ),
    true,
    'col_default_is( tab, col, int )',
    'Column sometab."myNum" should default to ''24''',
    ''
);

        -- We can handle DEFAULT NULL correctly.
SELECT * FROM check_test(
    col_default_is( 'sometab', 'numb', NULL::numeric, 'desc' ),
    true,
    'col_default_is( tab, col, NULL, desc )',
    'desc',
    ''
);

SELECT * FROM check_test(
    col_default_is( 'sometab', 'numb', NULL::numeric ),
    true,
    'col_default_is( tab, col, NULL )',
    'Column sometab.numb should default to NULL',
    ''
);

-- Make sure that it fails when there is no default.
SELECT * FROM check_test(
    col_default_is( 'sometab', 'plain', 1, 'desc' ),
    false,
    'col_default_is( tab, col, bogus, desc )',
    'desc',
    '    Column sometab.plain has no default'
);

SELECT * FROM check_test(
    col_default_is( 'sometab', 'plain', 1 ),
    false,
    'col_default_is( tab, col, bogus )',
    'Column sometab.plain should default to ''1''',
    '    Column sometab.plain has no default'
);

-- Make sure that it works when the default is an expression.
SELECT * FROM check_test(
    col_default_is( 'sometab', 'myat', 'now()' ),
    true,
    'col_default_is( tab, col, expression )',
    'Column sometab.myat should default to ''now()''',
    ''
);
SELECT * FROM check_test(
    col_default_is( 'sometab', 'myat', 'now()'::text ),
    true,
    'col_default_is( tab, col, expression::text )',
    'Column sometab.myat should default to ''now()''',
    ''
);
SELECT * FROM check_test(
    col_default_is( 'sometab', 'myat', 'now()', 'desc' ),
    true,
    'col_default_is( tab, col, expression, desc )',
    'desc',
    ''
);
SELECT * FROM check_test(
    col_default_is( 'sometab', 'myat', 'now()', 'desc'::text ),
    true,
    'col_default_is( tab, col, expression, desc )',
    'desc',
    ''
);
SELECT * FROM check_test(
    col_default_is( 'public', 'sometab', 'myat', 'now()', 'desc' ),
    true,
    'col_default_is( schema, tab, col, expression, desc )',
    'desc',
    ''
);
SELECT * FROM check_test(
    col_default_is( 'public', 'sometab', 'myat', 'now()', 'desc'::text ),
    true,
    'col_default_is( schema, tab, col, expression, desc )',
    'desc',
    ''
);

-- Check with a nonexistent column.
SELECT * FROM check_test(
    col_default_is( 'public', 'sometab', '__asdfasdfs__', NULL::text, 'desc' ),
    false,
    'col_default_is( sch, tab, col, def, desc )',
    'desc',
    '    Column public.sometab.__asdfasdfs__ does not exist'
);
SELECT * FROM check_test(
    col_default_is( 'sometab', '__asdfasdfs__', NULL::text, 'desc' ),
    false,
    'col_default_is( tab, col, def, desc )',
    'desc',
    '    Column sometab.__asdfasdfs__ does not exist'
);
SELECT * FROM check_test(
    col_default_is( 'sometab', '__asdfasdfs__', NULL::text ),
    false,
    'col_default_is( tab, col, def )',
    'Column sometab.__asdfasdfs__ should default to NULL',
    '    Column sometab.__asdfasdfs__ does not exist'
);

-- Make sure that it works when the default is a reserved SQL expression.
CREATE OR REPLACE FUNCTION ckreserve() RETURNS SETOF TEXT LANGUAGE PLPGSQL AS $$
DECLARE
    funcs text[] := '{CURRENT_CATALOG,CURRENT_ROLE,CURRENT_SCHEMA,CURRENT_USER,SESSION_USER,USER,CURRENT_DATE,CURRENT_TIME,CURRENT_TIMESTAMP,LOCALTIME,LOCALTIMESTAMP}';
    cols  TEXT[] := '{ccat,crole,csch,cuser,suser,auser,cdate,ctime,ctstz,ltime,ltstz}';
    exp   TEXT[] := funcs;
    tap           record;
    last_index    INTEGER;
BEGIN
    last_index := array_upper(funcs, 1);
    IF pg_version_num() < 100000 THEN
       -- Prior to PostgreSQL 10, these were functions rendered with paretheses or as casts.
       exp := ARRAY['current_database()','"current_user"()','"current_schema"()','"current_user"()','"session_user"()','"current_user"()','(''now''::text)::date','(''now''::text)::time with time zone','now()','(''now''::text)::time without time zone','(''now''::text)::timestamp without time zone'];
    END IF;

    FOR i IN 1..last_index LOOP
        FOR tap IN SELECT * FROM check_test(
            col_default_is( 'sometab', cols[i], exp[i], 'Test ' || funcs[i] ),
            true,
            'col_default_is( tab, col, ' || funcs[i] || ' )',
            'Test ' || funcs[i],
            ''
        ) AS b LOOP RETURN NEXT tap.b; END LOOP;
    END LOOP;
END;
$$;
SELECT * FROM ckreserve();

/****************************************************************************/
-- Finish the tests and clean up.
SELECT * FROM finish();
ROLLBACK;