* expandTupleDesc -- expandRTE subroutine * * Generate names and/or Vars for the first "count" attributes of the tupdesc, * and append them to colnames/colvars. "offset" is added to the varattno * that each Var would otherwise have, and we also skip the first "offset" * entries in eref->colnames. (These provisions allow use of this code for * an individual composite-returning function in a
| 3286 | * an individual composite-returning function in an RTE_FUNCTION RTE.) |
| 3287 | */ |
| 3288 | static void |
| 3289 | expandTupleDesc(TupleDesc tupdesc, Alias *eref, int count, int offset, |
| 3290 | int rtindex, int sublevels_up, |
| 3291 | int location, bool include_dropped, |
| 3292 | List **colnames, List **colvars, bool is_ivm) |
| 3293 | { |
| 3294 | ListCell *aliascell; |
| 3295 | int varattno; |
| 3296 | |
| 3297 | aliascell = (offset < list_length(eref->colnames)) ? |
| 3298 | list_nth_cell(eref->colnames, offset) : NULL; |
| 3299 | |
| 3300 | Assert(count <= tupdesc->natts); |
| 3301 | for (varattno = 0; varattno < count; varattno++) |
| 3302 | { |
| 3303 | Form_pg_attribute attr = TupleDescAttr(tupdesc, varattno); |
| 3304 | |
| 3305 | if (is_ivm && isIvmName(NameStr(attr->attname)) && !MatViewIncrementalMaintenanceIsEnabled()) |
| 3306 | continue; |
| 3307 | |
| 3308 | if (attr->attisdropped) |
| 3309 | { |
| 3310 | if (include_dropped) |
| 3311 | { |
| 3312 | if (colnames) |
| 3313 | *colnames = lappend(*colnames, makeString(pstrdup(""))); |
| 3314 | if (colvars) |
| 3315 | { |
| 3316 | /* |
| 3317 | * can't use atttypid here, but it doesn't really matter |
| 3318 | * what type the Const claims to be. |
| 3319 | */ |
| 3320 | *colvars = lappend(*colvars, |
| 3321 | makeNullConst(INT4OID, -1, InvalidOid)); |
| 3322 | } |
| 3323 | } |
| 3324 | if (aliascell) |
| 3325 | aliascell = lnext(eref->colnames, aliascell); |
| 3326 | continue; |
| 3327 | } |
| 3328 | |
| 3329 | if (colnames) |
| 3330 | { |
| 3331 | char *label; |
| 3332 | |
| 3333 | if (aliascell) |
| 3334 | { |
| 3335 | label = strVal(lfirst(aliascell)); |
| 3336 | aliascell = lnext(eref->colnames, aliascell); |
| 3337 | } |
| 3338 | else |
| 3339 | { |
| 3340 | /* If we run out of aliases, use the underlying name */ |
| 3341 | label = NameStr(attr->attname); |
| 3342 | } |
| 3343 | *colnames = lappend(*colnames, makeString(pstrdup(label))); |
| 3344 | } |
| 3345 |
no test coverage detected