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

Function defGetTypeLength

src/backend/commands/define.c:282–321  ·  view source on GitHub ↗

* Extract a type length indicator (either absolute bytes, or * -1 for "variable") from a DefElem. */

Source from the content-addressed store, hash-verified

280 * -1 for "variable") from a DefElem.
281 */
282int
283defGetTypeLength(DefElem *def)
284{
285 if (def->arg == NULL)
286 ereport(ERROR,
287 (errcode(ERRCODE_SYNTAX_ERROR),
288 errmsg("%s requires a parameter",
289 def->defname)));
290 switch (nodeTag(def->arg))
291 {
292 case T_Integer:
293 return intVal(def->arg);
294 case T_Float:
295 ereport(ERROR,
296 (errcode(ERRCODE_SYNTAX_ERROR),
297 errmsg("%s requires an integer value",
298 def->defname)));
299 break;
300 case T_String:
301 if (pg_strcasecmp(strVal(def->arg), "variable") == 0)
302 return -1; /* variable length */
303 break;
304 case T_TypeName:
305 /* cope if grammar chooses to believe "variable" is a typename */
306 if (pg_strcasecmp(TypeNameToString((TypeName *) def->arg),
307 "variable") == 0)
308 return -1; /* variable length */
309 break;
310 case T_List:
311 /* must be an operator name */
312 break;
313 default:
314 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(def->arg));
315 }
316 ereport(ERROR,
317 (errcode(ERRCODE_SYNTAX_ERROR),
318 errmsg("invalid argument for %s: \"%s\"",
319 def->defname, defGetString(def))));
320 return 0; /* keep compiler quiet */
321}
322
323/*
324 * Extract a list of string values (otherwise uninterpreted) from a DefElem.

Callers 1

DefineTypeFunction · 0.85

Calls 5

pg_strcasecmpFunction · 0.85
TypeNameToStringFunction · 0.85
defGetStringFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected