MCPcopy Create free account
hub / github.com/apache/cloudberry / postgresIsForeignRelUpdatable

Function postgresIsForeignRelUpdatable

contrib/postgres_fdw/postgres_fdw.c:2289–2338  ·  view source on GitHub ↗

* postgresIsForeignRelUpdatable * Determine whether a foreign table supports INSERT, UPDATE and/or * DELETE. */

Source from the content-addressed store, hash-verified

2287 * DELETE.
2288 */
2289static int
2290postgresIsForeignRelUpdatable(Relation rel)
2291{
2292 bool updatable;
2293 ForeignTable *table;
2294 ForeignServer *server;
2295 ListCell *lc;
2296
2297 /*
2298 * By default, all postgres_fdw foreign tables are assumed updatable. This
2299 * can be overridden by a per-server setting, which in turn can be
2300 * overridden by a per-table setting.
2301 */
2302 updatable = true;
2303
2304 table = GetForeignTable(RelationGetRelid(rel));
2305 server = GetForeignServer(table->serverid);
2306
2307 foreach(lc, server->options)
2308 {
2309 DefElem *def = (DefElem *) lfirst(lc);
2310
2311 if (strcmp(def->defname, "updatable") == 0)
2312 updatable = defGetBoolean(def);
2313 }
2314 foreach(lc, table->options)
2315 {
2316 DefElem *def = (DefElem *) lfirst(lc);
2317
2318 if (strcmp(def->defname, "updatable") == 0)
2319 updatable = defGetBoolean(def);
2320 }
2321
2322 /*
2323 * Currently "updatable" means support for INSERT, UPDATE and DELETE.
2324 */
2325 if (!updatable)
2326 return 0;
2327
2328 /*
2329 * Cloudberry only supports INSERT, because UPDATE/DELETE SELECT requires
2330 * the hidden column gp_segment_id and the other "ModifyTable mixes
2331 * distributed and entry-only tables" issue.
2332 */
2333 UserMapping *user = GetUserMapping(rel->rd_rel->relowner, table->serverid);
2334 if (greenplumCheckIsCloudberry(user))
2335 return (1 << CMD_INSERT);
2336 else
2337 return (1 << CMD_INSERT) | (1 << CMD_UPDATE) | (1 << CMD_DELETE);
2338}
2339
2340/*
2341 * postgresRecheckForeignScan

Callers

nothing calls this directly

Calls 6

GetForeignTableFunction · 0.85
GetForeignServerFunction · 0.85
defGetBooleanFunction · 0.85
GetUserMappingFunction · 0.85
foreachFunction · 0.50

Tested by

no test coverage detected