PostgreSQL Source Code git master
Loading...
Searching...
No Matches
define.c File Reference
#include "postgres.h"
#include <ctype.h>
#include "catalog/namespace.h"
#include "commands/defrem.h"
#include "nodes/makefuncs.h"
#include "parser/parse_type.h"
#include "utils/fmgrprotos.h"
Include dependency graph for define.c:

Go to the source code of this file.

Functions

chardefGetString (DefElem *def)
 
double defGetNumeric (DefElem *def)
 
bool defGetBoolean (DefElem *def)
 
int32 defGetInt32 (DefElem *def)
 
int64 defGetInt64 (DefElem *def)
 
Oid defGetObjectId (DefElem *def)
 
ListdefGetQualifiedName (DefElem *def)
 
TypeNamedefGetTypeName (DefElem *def)
 
int defGetTypeLength (DefElem *def)
 
ListdefGetStringList (DefElem *def)
 
void errorConflictingDefElem (DefElem *defel, ParseState *pstate)
 

Function Documentation

◆ defGetBoolean()

bool defGetBoolean ( DefElem def)

Definition at line 93 of file define.c.

94{
95 /*
96 * If no parameter value given, assume "true" is meant.
97 */
98 if (def->arg == NULL)
99 return true;
100
101 /*
102 * Allow 0, 1, "true", "false", "on", "off"
103 */
104 switch (nodeTag(def->arg))
105 {
106 case T_Integer:
107 switch (intVal(def->arg))
108 {
109 case 0:
110 return false;
111 case 1:
112 return true;
113 default:
114 /* otherwise, error out below */
115 break;
116 }
117 break;
118 default:
119 {
120 char *sval = defGetString(def);
121
122 /*
123 * The set of strings accepted here should match up with the
124 * grammar's opt_boolean_or_string production.
125 */
126 if (pg_strcasecmp(sval, "true") == 0)
127 return true;
128 if (pg_strcasecmp(sval, "false") == 0)
129 return false;
130 if (pg_strcasecmp(sval, "on") == 0)
131 return true;
132 if (pg_strcasecmp(sval, "off") == 0)
133 return false;
134 }
135 break;
136 }
139 errmsg("%s requires a Boolean value",
140 def->defname)));
141 return false; /* keep compiler quiet */
142}
char * defGetString(DefElem *def)
Definition define.c:34
int errcode(int sqlerrcode)
Definition elog.c:863
int errmsg(const char *fmt,...)
Definition elog.c:1080
#define ERROR
Definition elog.h:39
#define ereport(elevel,...)
Definition elog.h:150
#define nodeTag(nodeptr)
Definition nodes.h:139
int pg_strcasecmp(const char *s1, const char *s2)
static int fb(int x)
char * defname
Definition parsenodes.h:844
Node * arg
Definition parsenodes.h:845
#define intVal(v)
Definition value.h:79

References DefElem::arg, defGetString(), DefElem::defname, ereport, errcode(), errmsg(), ERROR, fb(), intVal, nodeTag, and pg_strcasecmp().

Referenced by AlterDatabase(), AlterOperator(), AlterReplicationSlot(), apply_server_options(), apply_table_options(), cluster(), createdb(), CreateExtension(), DefineAggregate(), DefineCollation(), DefineOperator(), DefineType(), dintdict_init(), dsimple_init(), dsynonym_init(), dxsyn_init(), ExecCheckpoint(), ExecReindex(), ExecVacuum(), ExecWaitStmt(), file_fdw_validator(), get_file_fdw_attribute_options(), get_vacoptval_from_boolean(), GetCommandLogLevel(), make_new_connection(), overexplain_debug_handler(), overexplain_range_table_handler(), parse_basebackup_options(), parse_output_parameters(), parse_publication_options(), parse_subscription_options(), parseCreateReplSlotOptions(), ParseExplainOptionList(), postgres_fdw_validator(), postgresExecForeignTruncate(), postgresImportForeignSchema(), postgresIsForeignRelUpdatable(), ProcessCopyOptions(), transformExplainStmt(), transformRelOptions(), UserMappingPasswordRequired(), UseScramPassthrough(), and UseScramPassthrough().

◆ defGetInt32()

int32 defGetInt32 ( DefElem def)

Definition at line 148 of file define.c.

149{
150 if (def->arg == NULL)
153 errmsg("%s requires an integer value",
154 def->defname)));
155 switch (nodeTag(def->arg))
156 {
157 case T_Integer:
158 return (int32) intVal(def->arg);
159 default:
162 errmsg("%s requires an integer value",
163 def->defname)));
164 }
165 return 0; /* keep compiler quiet */
166}
int32_t int32
Definition c.h:542

References DefElem::arg, DefElem::defname, ereport, errcode(), errmsg(), ERROR, fb(), intVal, and nodeTag.

Referenced by AlterDatabase(), ATExecSetIdentity(), createdb(), DefineAggregate(), ExecVacuum(), and parse_subscription_options().

◆ defGetInt64()

int64 defGetInt64 ( DefElem def)

Definition at line 172 of file define.c.

173{
174 if (def->arg == NULL)
177 errmsg("%s requires a numeric value",
178 def->defname)));
179 switch (nodeTag(def->arg))
180 {
181 case T_Integer:
182 return (int64) intVal(def->arg);
183 case T_Float:
184
185 /*
186 * Values too large for int4 will be represented as Float
187 * constants by the lexer. Accept these if they are valid int8
188 * strings.
189 */
191 CStringGetDatum(castNode(Float, def->arg)->fval)));
192 default:
195 errmsg("%s requires a numeric value",
196 def->defname)));
197 }
198 return 0; /* keep compiler quiet */
199}
int64_t int64
Definition c.h:543
#define DirectFunctionCall1(func, arg1)
Definition fmgr.h:684
Datum int8in(PG_FUNCTION_ARGS)
Definition int8.c:50
#define castNode(_type_, nodeptr)
Definition nodes.h:182
static int64 DatumGetInt64(Datum X)
Definition postgres.h:413
static Datum CStringGetDatum(const char *X)
Definition postgres.h:380
Definition value.h:48

References DefElem::arg, castNode, CStringGetDatum(), DatumGetInt64(), DefElem::defname, DirectFunctionCall1, ereport, errcode(), errmsg(), ERROR, fb(), int8in(), intVal, and nodeTag.

Referenced by defGetCopyRejectLimitOption(), init_params(), and parse_basebackup_options().

◆ defGetNumeric()

double defGetNumeric ( DefElem def)

Definition at line 67 of file define.c.

68{
69 if (def->arg == NULL)
72 errmsg("%s requires a numeric value",
73 def->defname)));
74 switch (nodeTag(def->arg))
75 {
76 case T_Integer:
77 return (double) intVal(def->arg);
78 case T_Float:
79 return floatVal(def->arg);
80 default:
83 errmsg("%s requires a numeric value",
84 def->defname)));
85 }
86 return 0; /* keep compiler quiet */
87}
#define floatVal(v)
Definition value.h:80

References DefElem::arg, DefElem::defname, ereport, errcode(), errmsg(), ERROR, fb(), floatVal, intVal, and nodeTag.

Referenced by AlterFunction(), and compute_function_attributes().

◆ defGetObjectId()

Oid defGetObjectId ( DefElem def)

Definition at line 205 of file define.c.

206{
207 if (def->arg == NULL)
210 errmsg("%s requires a numeric value",
211 def->defname)));
212 switch (nodeTag(def->arg))
213 {
214 case T_Integer:
215 return (Oid) intVal(def->arg);
216 case T_Float:
217
218 /*
219 * Values too large for int4 will be represented as Float
220 * constants by the lexer. Accept these if they are valid OID
221 * strings.
222 */
224 CStringGetDatum(castNode(Float, def->arg)->fval)));
225 default:
228 errmsg("%s requires a numeric value",
229 def->defname)));
230 }
231 return 0; /* keep compiler quiet */
232}
Datum oidin(PG_FUNCTION_ARGS)
Definition oid.c:37
static Oid DatumGetObjectId(Datum X)
Definition postgres.h:252
unsigned int Oid

References DefElem::arg, castNode, CStringGetDatum(), DatumGetObjectId(), DefElem::defname, DirectFunctionCall1, ereport, errcode(), errmsg(), ERROR, fb(), intVal, nodeTag, and oidin().

Referenced by createdb().

◆ defGetQualifiedName()

List * defGetQualifiedName ( DefElem def)

Definition at line 238 of file define.c.

239{
240 if (def->arg == NULL)
243 errmsg("%s requires a parameter",
244 def->defname)));
245 switch (nodeTag(def->arg))
246 {
247 case T_TypeName:
248 return ((TypeName *) def->arg)->names;
249 case T_List:
250 return (List *) def->arg;
251 case T_String:
252 /* Allow quoted name for backwards compatibility */
253 return list_make1(def->arg);
254 default:
257 errmsg("argument of %s must be a name",
258 def->defname)));
259 }
260 return NIL; /* keep compiler quiet */
261}
#define NIL
Definition pg_list.h:68
#define list_make1(x1)
Definition pg_list.h:212
Definition pg_list.h:54

References DefElem::arg, DefElem::defname, ereport, errcode(), errmsg(), ERROR, fb(), list_make1, NIL, and nodeTag.

Referenced by AlterOperator(), AlterType(), DefineAggregate(), DefineCollation(), DefineOperator(), DefineRange(), DefineTSConfiguration(), DefineTSDictionary(), DefineType(), get_ts_parser_func(), get_ts_template_func(), init_params(), and interpret_func_support().

◆ defGetString()

char * defGetString ( DefElem def)

Definition at line 34 of file define.c.

35{
36 if (def->arg == NULL)
39 errmsg("%s requires a parameter",
40 def->defname)));
41 switch (nodeTag(def->arg))
42 {
43 case T_Integer:
44 return psprintf("%d", intVal(def->arg));
45 case T_Float:
46 return castNode(Float, def->arg)->fval;
47 case T_Boolean:
48 return boolVal(def->arg) ? "true" : "false";
49 case T_String:
50 return strVal(def->arg);
51 case T_TypeName:
52 return TypeNameToString((TypeName *) def->arg);
53 case T_List:
54 return NameListToString((List *) def->arg);
55 case T_A_Star:
56 return pstrdup("*");
57 default:
58 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(def->arg));
59 }
60 return NULL; /* keep compiler quiet */
61}
#define elog(elevel,...)
Definition elog.h:226
char * pstrdup(const char *in)
Definition mcxt.c:1781
char * NameListToString(const List *names)
Definition namespace.c:3664
char * TypeNameToString(const TypeName *typeName)
Definition parse_type.c:478
char * psprintf(const char *fmt,...)
Definition psprintf.c:43
#define boolVal(v)
Definition value.h:81
#define strVal(v)
Definition value.h:82

References DefElem::arg, boolVal, castNode, DefElem::defname, elog, ereport, errcode(), errmsg(), ERROR, fb(), intVal, NameListToString(), nodeTag, psprintf(), pstrdup(), strVal, and TypeNameToString().

Referenced by AlterDatabase(), AlterType(), apply_server_options(), apply_table_options(), check_selective_binary_conversion(), createdb(), CreateExtension(), defGetBoolean(), defGetCopyHeaderOption(), defGetCopyLogVerbosityChoice(), defGetCopyOnErrorChoice(), defGetGeneratedColsOption(), defGetStreamingMode(), defGetTypeLength(), DefineAggregate(), DefineCollation(), DefineType(), deparseAnalyzeSql(), deparseColumnRef(), deparseRelation(), dintdict_init(), dispell_init(), dsimple_init(), dsnowball_init(), dsynonym_init(), dxsyn_init(), ExecCheckpoint(), ExecReindex(), ExecVacuum(), ExecWaitStmt(), ExplainResultDesc(), ExtractConnectionOptions(), extractModify(), file_fdw_validator(), fileGetOptions(), get_batch_size_option(), GrantRole(), optionListToArray(), parse_basebackup_options(), parse_output_parameters(), parse_publication_options(), parse_subscription_options(), parseCreateReplSlotOptions(), ParseExplainOptionList(), postgres_fdw_validator(), postgresAcquireSampleRowsFunc(), ProcessCopyOptions(), prsd_headline(), serialize_deflist(), thesaurus_init(), transformRelOptions(), and unaccent_init().

◆ defGetStringList()

List * defGetStringList ( DefElem def)

Definition at line 342 of file define.c.

343{
344 ListCell *cell;
345
346 if (def->arg == NULL)
349 errmsg("%s requires a parameter",
350 def->defname)));
351 if (!IsA(def->arg, List))
352 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(def->arg));
353
354 foreach(cell, (List *) def->arg)
355 {
356 Node *str = (Node *) lfirst(cell);
357
358 if (!IsA(str, String))
359 elog(ERROR, "unexpected node type in name list: %d",
360 (int) nodeTag(str));
361 }
362
363 return (List *) def->arg;
364}
const char * str
#define IsA(nodeptr, _type_)
Definition nodes.h:164
#define lfirst(lc)
Definition pg_list.h:172
Definition nodes.h:135
Definition value.h:64

References DefElem::arg, DefElem::defname, elog, ereport, errcode(), errmsg(), ERROR, fb(), IsA, lfirst, nodeTag, and str.

◆ defGetTypeLength()

int defGetTypeLength ( DefElem def)

Definition at line 298 of file define.c.

299{
300 if (def->arg == NULL)
303 errmsg("%s requires a parameter",
304 def->defname)));
305 switch (nodeTag(def->arg))
306 {
307 case T_Integer:
308 return intVal(def->arg);
309 case T_Float:
312 errmsg("%s requires an integer value",
313 def->defname)));
314 break;
315 case T_String:
316 if (pg_strcasecmp(strVal(def->arg), "variable") == 0)
317 return -1; /* variable length */
318 break;
319 case T_TypeName:
320 /* cope if grammar chooses to believe "variable" is a typename */
322 "variable") == 0)
323 return -1; /* variable length */
324 break;
325 case T_List:
326 /* must be an operator name */
327 break;
328 default:
329 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(def->arg));
330 }
333 errmsg("invalid argument for %s: \"%s\"",
334 def->defname, defGetString(def))));
335 return 0; /* keep compiler quiet */
336}

References DefElem::arg, defGetString(), DefElem::defname, elog, ereport, errcode(), errmsg(), ERROR, fb(), intVal, nodeTag, pg_strcasecmp(), strVal, and TypeNameToString().

Referenced by DefineType().

◆ defGetTypeName()

TypeName * defGetTypeName ( DefElem def)

Definition at line 270 of file define.c.

271{
272 if (def->arg == NULL)
275 errmsg("%s requires a parameter",
276 def->defname)));
277 switch (nodeTag(def->arg))
278 {
279 case T_TypeName:
280 return (TypeName *) def->arg;
281 case T_String:
282 /* Allow quoted typename for backwards compatibility */
284 default:
287 errmsg("argument of %s must be a type name",
288 def->defname)));
289 }
290 return NULL; /* keep compiler quiet */
291}
TypeName * makeTypeNameFromNameList(List *names)
Definition makefuncs.c:531

References DefElem::arg, DefElem::defname, ereport, errcode(), errmsg(), ERROR, fb(), list_make1, makeTypeNameFromNameList(), and nodeTag.

Referenced by DefineAggregate(), DefineOperator(), DefineRange(), DefineType(), and init_params().

◆ errorConflictingDefElem()