Skip to content

Commit

Permalink
Add tag for database object
Browse files Browse the repository at this point in the history
  • Loading branch information
wenchaozhang-123 committed May 24, 2024
1 parent 4d3ab62 commit 6377343
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/backend/commands/dbcommands.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include "commands/defrem.h"
#include "commands/seclabel.h"
#include "commands/tablespace.h"
#include "commands/tag.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "pgstat.h"
Expand Down Expand Up @@ -583,6 +584,18 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
RememberAssignedOidForDatabase(dbname, dboid);
}

if (stmt->tags)
{
ListCell *cell;
foreach(cell, stmt->tags)
{
DefElem *def;

def = lfirst(cell);
AddTagForObject(def);
}
}

/*
* Insert a new tuple into pg_database. This establishes our ownership of
* the new database name (anyone else trying to insert the same name will
Expand Down
20 changes: 20 additions & 0 deletions src/backend/commands/tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,20 @@ RenameTag(const char *oldname, const char *newname)
return address;
}

/*
* Add tag
*
* Add tag for database object such as database, warehouse, table etc.
*/
void
AddTagForObject(DefElem *def)
{
return;
}

/*
* Transform tag allowed values to datum.
*/
static Datum
transformTagAllowedValues(int action, Datum oldvalues,
List *allowed_values)
Expand Down Expand Up @@ -489,6 +503,9 @@ transformTagAllowedValues(int action, Datum oldvalues,
return result;
}

/*
* Untranform tag values from datum to list.
*/
static List *
untransformTagValues(Datum allowed_values)
{
Expand Down Expand Up @@ -521,6 +538,9 @@ untransformTagValues(Datum allowed_values)
return result;
}

/*
* Get array datum from allowed_values list.
*/
static Datum
valueListToArray(List *allowed_values)
{
Expand Down
1 change: 0 additions & 1 deletion src/backend/parser/gram.y
Original file line number Diff line number Diff line change
Expand Up @@ -2501,7 +2501,6 @@ OptTagValuesList:

OptTagOptList:
TAG '(' TagOptList ')' { $$ = $3; }
| WITH TAG '(' TagOptList ')' { $$ = $4; }
| /*EMPTY*/ { $$ = NIL; }
;

Expand Down
1 change: 1 addition & 0 deletions src/include/commands/tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
extern Oid CreateTag(CreateTagStmt *stmt);
extern ObjectAddress AlterTag(AlterTagStmt *stmt);
extern void DropTag(DropTagStmt *stmt);
extern void AddTagForObject(DefElem *def);
extern Oid get_tag_oid(const char *tagname, bool missing_ok);
extern ObjectAddress RenameTag(const char *oldname, const char *newname);

Expand Down

0 comments on commit 6377343

Please sign in to comment.