修复pg_get_tabledef对on update timestamp属于显示,表达式转换关键字处理

This commit is contained in:
lvhui
2022-09-19 01:44:48 -07:00
parent 56bd9900e2
commit 81fee7373b

View File

@ -1645,7 +1645,40 @@ static int get_table_attribute(
appendStringInfo(buf, " DEFAULT %s", adsrc);
}
if (isOnUpdate) {
appendStringInfo(buf, " ON UPDATE %s", TextDatumGetCString(onUpdateExpr));
if (pg_strcasecmp(TextDatumGetCString(onUpdateExpr), "pg_systimestamp()") == 0) {
appendStringInfo(buf, " ON UPDATE CURRENT_TIMESTAMP");
} else if (pg_strcasecmp(TextDatumGetCString(onUpdateExpr), "('now'::text)::time with time zone") == 0) {
appendStringInfo(buf, " ON UPDATE CURRENT_TIME");
} else if (pg_strcasecmp(TextDatumGetCString(onUpdateExpr), "text_date('now'::text)") == 0) {
appendStringInfo(buf, " ON UPDATE CURRENT_DATE");
} else if (pg_strcasecmp(TextDatumGetCString(onUpdateExpr), "('now'::text)::time without time zone") == 0) {
appendStringInfo(buf, " ON UPDATE LOCALTIME");
} else if (pg_strcasecmp(TextDatumGetCString(onUpdateExpr), "('now'::text)::timestamp without time zone") == 0) {
appendStringInfo(buf, " ON UPDATE LOCALTIMESTAMP");
} else {
char* size_start = NULL;
char* size_end = NULL;
int number_size = 0;
size_start = strstr(TextDatumGetCString(onUpdateExpr), "timestamp(");
if (size_start != NULL) {
size_start = size_start + 10;
size_end = strstr(size_start, ")");
number_size = size_end - size_start;
char num[number_size + 1] = {0};
strncpy(num, size_start, number_size);
appendStringInfo(buf, " ON UPDATE CURRENT_TIMESTAMP(%s)", num);
} else {
size_start = strstr(TextDatumGetCString(onUpdateExpr), "time(");
if (size_start != NULL) {
size_start = size_start + 5;
size_end = strstr(size_start, ")");
number_size = size_end - size_start;
char num[number_size + 1] = {0};
strncpy(num, size_start, number_size);
appendStringInfo(buf, " ON UPDATE CURRENT_TIME(%s)", num);
}
}
}
}
break;
}