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

Function get_sql_insert

contrib/dblink/dblink.c:2188–2266  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2186}
2187
2188static char *
2189get_sql_insert(Relation rel, int *pkattnums, int pknumatts, char **src_pkattvals, char **tgt_pkattvals)
2190{
2191 char *relname;
2192 HeapTuple tuple;
2193 TupleDesc tupdesc;
2194 int natts;
2195 StringInfoData buf;
2196 char *val;
2197 int key;
2198 int i;
2199 bool needComma;
2200
2201 initStringInfo(&buf);
2202
2203 /* get relation name including any needed schema prefix and quoting */
2204 relname = generate_relation_name(rel);
2205
2206 tupdesc = rel->rd_att;
2207 natts = tupdesc->natts;
2208
2209 tuple = get_tuple_of_interest(rel, pkattnums, pknumatts, src_pkattvals);
2210 if (!tuple)
2211 ereport(ERROR,
2212 (errcode(ERRCODE_CARDINALITY_VIOLATION),
2213 errmsg("source row not found")));
2214
2215 appendStringInfo(&buf, "INSERT INTO %s(", relname);
2216
2217 needComma = false;
2218 for (i = 0; i < natts; i++)
2219 {
2220 Form_pg_attribute att = TupleDescAttr(tupdesc, i);
2221
2222 if (att->attisdropped)
2223 continue;
2224
2225 if (needComma)
2226 appendStringInfoChar(&buf, ',');
2227
2228 appendStringInfoString(&buf,
2229 quote_ident_cstr(NameStr(att->attname)));
2230 needComma = true;
2231 }
2232
2233 appendStringInfoString(&buf, ") VALUES(");
2234
2235 /*
2236 * Note: i is physical column number (counting from 0).
2237 */
2238 needComma = false;
2239 for (i = 0; i < natts; i++)
2240 {
2241 if (TupleDescAttr(tupdesc, i)->attisdropped)
2242 continue;
2243
2244 if (needComma)
2245 appendStringInfoChar(&buf, ',');

Callers 1

dblink_build_sql_insertFunction · 0.85

Calls 14

initStringInfoFunction · 0.85
get_tuple_of_interestFunction · 0.85
appendStringInfoFunction · 0.85
appendStringInfoCharFunction · 0.85
appendStringInfoStringFunction · 0.85
quote_ident_cstrFunction · 0.85
get_attnum_pk_posFunction · 0.85
SPI_getvalueFunction · 0.85
quote_literal_cstrFunction · 0.85
generate_relation_nameFunction · 0.70
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected