Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc3b3c7c

Browse files
author
Nikita Glukhov
committed
Add ALTER TYPE
1 parent7bd0ebc commitc3b3c7c

File tree

9 files changed

+141
-2
lines changed

9 files changed

+141
-2
lines changed

‎src/backend/commands/typecmds.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3622,3 +3622,29 @@ AlterTypeNamespaceInternal(Oid typeOid, Oid nspOid,
36223622

36233623
returnoldNspOid;
36243624
}
3625+
3626+
/*
3627+
* Execute ALTER TYPE <typeName> <command>, ...
3628+
*/
3629+
void
3630+
AlterType(AlterTypeStmt*stmt)
3631+
{
3632+
TypeName*typename;
3633+
Oidtypeid;
3634+
ListCell*lcmd;
3635+
3636+
/* Make a TypeName so we can use standard type lookup machinery */
3637+
typename=makeTypeNameFromNameList(stmt->typeName);
3638+
typeid=typenameTypeId(NULL,typename);
3639+
3640+
foreach(lcmd,stmt->cmds)
3641+
{
3642+
AlterTypeCmd*cmd= (AlterTypeCmd*)lfirst(lcmd);
3643+
3644+
switch (cmd->cmdtype)
3645+
{
3646+
default:
3647+
elog(ERROR,"unknown ALTER TYPE command %d",cmd->cmdtype);
3648+
}
3649+
}
3650+
}

‎src/backend/nodes/copyfuncs.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4556,6 +4556,28 @@ _copyDropSubscriptionStmt(const DropSubscriptionStmt *from)
45564556
returnnewnode;
45574557
}
45584558

4559+
staticAlterTypeStmt*
4560+
_copyAlterTypeStmt(constAlterTypeStmt*from)
4561+
{
4562+
AlterTypeStmt*newnode=makeNode(AlterTypeStmt);
4563+
4564+
COPY_NODE_FIELD(typeName);
4565+
COPY_NODE_FIELD(cmds);
4566+
4567+
returnnewnode;
4568+
}
4569+
4570+
staticAlterTypeCmd*
4571+
_copyAlterTypeCmd(constAlterTypeCmd*from)
4572+
{
4573+
AlterTypeCmd*newnode=makeNode(AlterTypeCmd);
4574+
4575+
COPY_SCALAR_FIELD(cmdtype);
4576+
COPY_NODE_FIELD(def);
4577+
4578+
returnnewnode;
4579+
}
4580+
45594581
/* ****************************************************************
45604582
*pg_list.h copy functions
45614583
* ****************************************************************
@@ -5550,6 +5572,14 @@ copyObjectImpl(const void *from)
55505572
retval=_copyForeignKeyCacheInfo(from);
55515573
break;
55525574

5575+
caseT_AlterTypeStmt:
5576+
retval=_copyAlterTypeStmt(from);
5577+
break;
5578+
5579+
caseT_AlterTypeCmd:
5580+
retval=_copyAlterTypeCmd(from);
5581+
break;
5582+
55535583
default:
55545584
elog(ERROR,"unrecognized node type: %d", (int)nodeTag(from));
55555585
retval=0;/* keep compiler quiet */

‎src/backend/nodes/equalfuncs.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2875,6 +2875,24 @@ _equalPartitionCmd(const PartitionCmd *a, const PartitionCmd *b)
28752875
return true;
28762876
}
28772877

2878+
staticbool
2879+
_equalAlterTypeStmt(constAlterTypeStmt*a,constAlterTypeStmt*b)
2880+
{
2881+
COMPARE_NODE_FIELD(typeName);
2882+
COMPARE_NODE_FIELD(cmds);
2883+
2884+
return true;
2885+
}
2886+
2887+
staticbool
2888+
_equalAlterTypeCmd(constAlterTypeCmd*a,constAlterTypeCmd*b)
2889+
{
2890+
COMPARE_SCALAR_FIELD(cmdtype);
2891+
COMPARE_NODE_FIELD(def);
2892+
2893+
return true;
2894+
}
2895+
28782896
/*
28792897
* Stuff from pg_list.h
28802898
*/
@@ -3688,6 +3706,12 @@ equal(const void *a, const void *b)
36883706
caseT_PartitionCmd:
36893707
retval=_equalPartitionCmd(a,b);
36903708
break;
3709+
caseT_AlterTypeStmt:
3710+
retval=_equalAlterTypeStmt(a,b);
3711+
break;
3712+
caseT_AlterTypeCmd:
3713+
retval=_equalAlterTypeCmd(a,b);
3714+
break;
36913715

36923716
default:
36933717
elog(ERROR,"unrecognized node type: %d",

‎src/backend/parser/gram.y

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
282282
CreateMatViewStmtRefreshMatViewStmtCreateAmStmt
283283
CreatePublicationStmtAlterPublicationStmt
284284
CreateSubscriptionStmtAlterSubscriptionStmtDropSubscriptionStmt
285+
AlterTypeStmt
285286

286287
%type<node>select_no_parensselect_with_parensselect_clause
287288
simple_selectvalues_clause
@@ -290,8 +291,8 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
290291
%type<ival>add_dropopt_asc_descopt_nulls_order
291292

292293
%type<node>alter_table_cmdalter_type_cmdopt_collate_clause
293-
replica_identitypartition_cmd
294-
%type<list>alter_table_cmdsalter_type_cmds
294+
replica_identitypartition_cmdalterTypeCmd
295+
%type<list>alter_table_cmdsalter_type_cmdsalterTypeCmds
295296
%type<list>alter_identity_column_option_list
296297
%type<defelt>alter_identity_column_option
297298

@@ -846,6 +847,7 @@ stmt :
846847
|AlterSubscriptionStmt
847848
|AlterTSConfigurationStmt
848849
|AlterTSDictionaryStmt
850+
|AlterTypeStmt
849851
|AlterUserMappingStmt
850852
|AlterUserSetStmt
851853
|AlterUserStmt
@@ -2740,6 +2742,25 @@ PartitionRangeDatum:
27402742
* really variants of the ALTER TABLE subcommands with different spellings
27412743
*****************************************************************************/
27422744

2745+
AlterTypeStmt:
2746+
ALTERTYPE_Pany_namealterTypeCmds
2747+
{
2748+
AlterTypeStmt *n = makeNode(AlterTypeStmt);
2749+
n->typeName =$3;
2750+
n->cmds =$4;
2751+
$$ = (Node *) n;
2752+
}
2753+
;
2754+
2755+
alterTypeCmds:
2756+
alterTypeCmd{$$ = list_make1($1); }
2757+
|alterTypeCmds','alterTypeCmd{$$ = lappend($1,$3); }
2758+
;
2759+
2760+
alterTypeCmd:
2761+
/*EMPTY*/
2762+
;
2763+
27432764
AlterCompositeTypeStmt:
27442765
ALTERTYPE_Pany_namealter_type_cmds
27452766
{

‎src/backend/tcop/utility.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ check_xact_readonly(Node *parsetree)
217217
caseT_CreateSubscriptionStmt:
218218
caseT_AlterSubscriptionStmt:
219219
caseT_DropSubscriptionStmt:
220+
caseT_AlterTypeStmt:
220221
PreventCommandIfReadOnly(CreateCommandTag(parsetree));
221222
PreventCommandIfParallelMode(CreateCommandTag(parsetree));
222223
break;
@@ -1652,6 +1653,10 @@ ProcessUtilitySlow(ParseState *pstate,
16521653
address=AlterCollation((AlterCollationStmt*)parsetree);
16531654
break;
16541655

1656+
caseT_AlterTypeStmt:
1657+
AlterType((AlterTypeStmt*)parsetree);
1658+
break;
1659+
16551660
default:
16561661
elog(ERROR,"unrecognized node type: %d",
16571662
(int)nodeTag(parsetree));
@@ -2866,6 +2871,10 @@ CreateCommandTag(Node *parsetree)
28662871
}
28672872
break;
28682873

2874+
caseT_AlterTypeStmt:
2875+
tag="ALTER TYPE";
2876+
break;
2877+
28692878
default:
28702879
elog(WARNING,"unrecognized node type: %d",
28712880
(int)nodeTag(parsetree));
@@ -3311,6 +3320,10 @@ GetCommandLogLevel(Node *parsetree)
33113320
lev=LOGSTMT_DDL;
33123321
break;
33133322

3323+
caseT_AlterTypeStmt:
3324+
lev=LOGSTMT_DDL;
3325+
break;
3326+
33143327
/* already-planned queries */
33153328
caseT_PlannedStmt:
33163329
{

‎src/include/commands/typecmds.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,6 @@ extern Oid AlterTypeNamespaceInternal(Oid typeOid, Oid nspOid,
5353
boolisImplicitArray,
5454
boolerrorOnTableType,
5555
ObjectAddresses*objsMoved);
56+
externvoidAlterType(AlterTypeStmt*stmt);
5657

5758
#endif/* TYPECMDS_H */

‎src/include/fmgr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#ifndefFMGR_H
1919
#defineFMGR_H
2020

21+
#include"utils/expandeddatum.h"
22+
2123
/* We don't want to include primnodes.h here, so make some stub references */
2224
typedefstructNode*fmNodePtr;
2325
typedefstructAggref*fmAggrefPtr;

‎src/include/nodes/nodes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,8 @@ typedef enum NodeTag
414414
T_DropSubscriptionStmt,
415415
T_CreateStatsStmt,
416416
T_AlterCollationStmt,
417+
T_AlterTypeStmt,
418+
T_AlterTypeCmd,
417419

418420
/*
419421
* TAGS FOR PARSE TREE NODES (parsenodes.h)

‎src/include/nodes/parsenodes.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3407,4 +3407,24 @@ typedef struct DropSubscriptionStmt
34073407
boolmissing_ok;/* Skip error if missing? */
34083408
}DropSubscriptionStmt;
34093409

3410+
3411+
typedefenumAlterTypeCmdType
3412+
{
3413+
AT_AlterTypeInvalidCommand
3414+
}AlterTypeCmdType;
3415+
3416+
typedefstructAlterTypeCmd
3417+
{
3418+
NodeTagtype;
3419+
AlterTypeCmdTypecmdtype;
3420+
Node*def;
3421+
}AlterTypeCmd;
3422+
3423+
typedefstructAlterTypeStmt
3424+
{
3425+
NodeTagtype;
3426+
List*typeName;
3427+
List*cmds;
3428+
}AlterTypeStmt;
3429+
34103430
#endif/* PARSENODES_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp