* Extract a string value (otherwise uninterpreted) from a DefElem. */
| 46 | * Extract a string value (otherwise uninterpreted) from a DefElem. |
| 47 | */ |
| 48 | char * |
| 49 | defGetString(DefElem *def) |
| 50 | { |
| 51 | if (def->arg == NULL) |
| 52 | ereport(ERROR, |
| 53 | (errcode(ERRCODE_SYNTAX_ERROR), |
| 54 | errmsg("%s requires a parameter", |
| 55 | def->defname))); |
| 56 | switch (nodeTag(def->arg)) |
| 57 | { |
| 58 | case T_Integer: |
| 59 | return psprintf("%ld", (long) intVal(def->arg)); |
| 60 | case T_Float: |
| 61 | |
| 62 | /* |
| 63 | * T_Float values are kept in string form, so this type cheat |
| 64 | * works (and doesn't risk losing precision) |
| 65 | */ |
| 66 | return strVal(def->arg); |
| 67 | case T_String: |
| 68 | return strVal(def->arg); |
| 69 | case T_TypeName: |
| 70 | return TypeNameToString((TypeName *) def->arg); |
| 71 | case T_List: |
| 72 | return NameListToString((List *) def->arg); |
| 73 | case T_A_Star: |
| 74 | return pstrdup("*"); |
| 75 | default: |
| 76 | elog(ERROR, "unrecognized node type: %d", (int) nodeTag(def->arg)); |
| 77 | } |
| 78 | return NULL; /* keep compiler quiet */ |
| 79 | } |
| 80 | |
| 81 | /* |
| 82 | * Extract a numeric value (actually double) from a DefElem. |
no test coverage detected