@@ -3242,6 +3242,100 @@ select * from int8_tbl a,
3242
3242
4567890123456789 | -4567890123456789 | 4567890123456789 | -4567890123456789 |
3243
3243
(57 rows)
3244
3244
3245
+ -- lateral references requiring pullup
3246
+ select * from (values(1)) x(lb),
3247
+ lateral generate_series(lb,4) x4;
3248
+ lb | x4
3249
+ ----+----
3250
+ 1 | 1
3251
+ 1 | 2
3252
+ 1 | 3
3253
+ 1 | 4
3254
+ (4 rows)
3255
+
3256
+ select * from (select f1/1000000000 from int4_tbl) x(lb),
3257
+ lateral generate_series(lb,4) x4;
3258
+ lb | x4
3259
+ ----+----
3260
+ 0 | 0
3261
+ 0 | 1
3262
+ 0 | 2
3263
+ 0 | 3
3264
+ 0 | 4
3265
+ 0 | 0
3266
+ 0 | 1
3267
+ 0 | 2
3268
+ 0 | 3
3269
+ 0 | 4
3270
+ 0 | 0
3271
+ 0 | 1
3272
+ 0 | 2
3273
+ 0 | 3
3274
+ 0 | 4
3275
+ 2 | 2
3276
+ 2 | 3
3277
+ 2 | 4
3278
+ -2 | -2
3279
+ -2 | -1
3280
+ -2 | 0
3281
+ -2 | 1
3282
+ -2 | 2
3283
+ -2 | 3
3284
+ -2 | 4
3285
+ (25 rows)
3286
+
3287
+ select * from (values(1)) x(lb),
3288
+ lateral (values(lb)) y(lbcopy);
3289
+ lb | lbcopy
3290
+ ----+--------
3291
+ 1 | 1
3292
+ (1 row)
3293
+
3294
+ select * from (values(1)) x(lb),
3295
+ lateral (select lb from int4_tbl) y(lbcopy);
3296
+ lb | lbcopy
3297
+ ----+--------
3298
+ 1 | 1
3299
+ 1 | 1
3300
+ 1 | 1
3301
+ 1 | 1
3302
+ 1 | 1
3303
+ (5 rows)
3304
+
3305
+ select * from
3306
+ int8_tbl x left join (select q1,coalesce(q2,0) q2 from int8_tbl) y on x.q2 = y.q1,
3307
+ lateral (values(x.q1,y.q1,y.q2)) v(xq1,yq1,yq2);
3308
+ q1 | q2 | q1 | q2 | xq1 | yq1 | yq2
3309
+ ------------------+-------------------+------------------+-------------------+------------------+------------------+-------------------
3310
+ 123 | 456 | | | 123 | |
3311
+ 123 | 4567890123456789 | 4567890123456789 | -4567890123456789 | 123 | 4567890123456789 | -4567890123456789
3312
+ 123 | 4567890123456789 | 4567890123456789 | 4567890123456789 | 123 | 4567890123456789 | 4567890123456789
3313
+ 123 | 4567890123456789 | 4567890123456789 | 123 | 123 | 4567890123456789 | 123
3314
+ 4567890123456789 | 123 | 123 | 4567890123456789 | 4567890123456789 | 123 | 4567890123456789
3315
+ 4567890123456789 | 123 | 123 | 456 | 4567890123456789 | 123 | 456
3316
+ 4567890123456789 | 4567890123456789 | 4567890123456789 | -4567890123456789 | 4567890123456789 | 4567890123456789 | -4567890123456789
3317
+ 4567890123456789 | 4567890123456789 | 4567890123456789 | 4567890123456789 | 4567890123456789 | 4567890123456789 | 4567890123456789
3318
+ 4567890123456789 | 4567890123456789 | 4567890123456789 | 123 | 4567890123456789 | 4567890123456789 | 123
3319
+ 4567890123456789 | -4567890123456789 | | | 4567890123456789 | |
3320
+ (10 rows)
3321
+
3322
+ select * from
3323
+ int8_tbl x left join (select q1,coalesce(q2,0) q2 from int8_tbl) y on x.q2 = y.q1,
3324
+ lateral (select x.q1,y.q1,y.q2) v(xq1,yq1,yq2);
3325
+ q1 | q2 | q1 | q2 | xq1 | yq1 | yq2
3326
+ ------------------+-------------------+------------------+-------------------+------------------+------------------+-------------------
3327
+ 123 | 456 | | | 123 | |
3328
+ 123 | 4567890123456789 | 4567890123456789 | -4567890123456789 | 123 | 4567890123456789 | -4567890123456789
3329
+ 123 | 4567890123456789 | 4567890123456789 | 4567890123456789 | 123 | 4567890123456789 | 4567890123456789
3330
+ 123 | 4567890123456789 | 4567890123456789 | 123 | 123 | 4567890123456789 | 123
3331
+ 4567890123456789 | 123 | 123 | 4567890123456789 | 4567890123456789 | 123 | 4567890123456789
3332
+ 4567890123456789 | 123 | 123 | 456 | 4567890123456789 | 123 | 456
3333
+ 4567890123456789 | 4567890123456789 | 4567890123456789 | -4567890123456789 | 4567890123456789 | 4567890123456789 | -4567890123456789
3334
+ 4567890123456789 | 4567890123456789 | 4567890123456789 | 4567890123456789 | 4567890123456789 | 4567890123456789 | 4567890123456789
3335
+ 4567890123456789 | 4567890123456789 | 4567890123456789 | 123 | 4567890123456789 | 4567890123456789 | 123
3336
+ 4567890123456789 | -4567890123456789 | | | 4567890123456789 | |
3337
+ (10 rows)
3338
+
3245
3339
-- test some error cases where LATERAL should have been used but wasn't
3246
3340
select f1,g from int4_tbl a, generate_series(0, f1) g;
3247
3341
ERROR: column "f1" does not exist
0 commit comments