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

Function DefineTask

src/backend/commands/taskcmds.c:47–145  ·  view source on GitHub ↗

* DefineTask * Create a new cron task. */

Source from the content-addressed store, hash-verified

45 * Create a new cron task.
46 */
47ObjectAddress
48DefineTask(ParseState *pstate, CreateTaskStmt * stmt)
49{
50 ObjectAddress address;
51 char *dbname = NULL;
52 char *username = NULL;
53 ListCell *option;
54 DefElem *d_dbname = NULL;
55 DefElem *d_username = NULL;
56 Oid jobid = InvalidOid;
57 AclResult aclresult;
58
59 /* must have CREATE privilege on database */
60 aclresult = pg_database_aclcheck(MyDatabaseId, GetUserId(), ACL_CREATE);
61 if (aclresult != ACLCHECK_OK)
62 aclcheck_error(aclresult, OBJECT_DATABASE,
63 get_database_name(MyDatabaseId));
64
65 foreach(option, stmt->options)
66 {
67 DefElem *defel = (DefElem *) lfirst(option);
68
69 if (strcmp(defel->defname, "dbname") == 0)
70 {
71 if (d_dbname)
72 ereport(ERROR,
73 (errcode(ERRCODE_SYNTAX_ERROR),
74 errmsg("conflicting or redundant options"),
75 parser_errposition(pstate, defel->location)));
76 d_dbname = defel;
77 }
78 else if (strcmp(defel->defname, "username") == 0)
79 {
80 if (d_username)
81 ereport(ERROR,
82 (errcode(ERRCODE_SYNTAX_ERROR),
83 errmsg("conflicting or redundant options"),
84 parser_errposition(pstate, defel->location)));
85 d_username = defel;
86 }
87 else
88 elog(ERROR, "option \"%s\" not recognized",
89 defel->defname);
90 }
91
92 /* use the specified or current user */
93 if (d_username != NULL && d_username->arg)
94 {
95 username = defGetString(d_username);
96 if (!OidIsValid(get_role_oid(username, false)))
97 ereport(ERROR,
98 (errcode(ERRCODE_UNDEFINED_OBJECT),
99 errmsg("role \"%s\" does not exist", username)));
100 }
101 else
102 username = GetUserNameFromId(GetUserId(), false);
103
104 /* use the specified or current database */

Callers 2

ProcessUtilitySlowFunction · 0.85

Calls 15

pg_database_aclcheckFunction · 0.85
GetUserIdFunction · 0.85
aclcheck_errorFunction · 0.85
get_database_nameFunction · 0.85
parser_errpositionFunction · 0.85
defGetStringFunction · 0.85
get_role_oidFunction · 0.85
GetUserNameFromIdFunction · 0.85
get_database_oidFunction · 0.85
GetTaskJobIdFunction · 0.85
ScheduleCronJobFunction · 0.85
cstring_to_textFunction · 0.85

Tested by

no test coverage detected