PostgreSQL 到 Oracle DDL

发布于 2024-12-09 17:23:49 字数 544 浏览 1 评论 0原文

我们正在使用 PostgreSQL(我们对此很满意!),但由于客户政策,我们需要在 Oracle 上运行我们的应用程序。不幸的是,我们的 ERD 充满了长度超过 30 个字符的标识符(列名和关系名)(甚至 21 世纪的 Oracle 11g 仍然无法消化它,ORA-00972!)。

您知道有什么工具可以帮助自动重命名长名称吗?
例如my_very_long_rel_from_table1_to_table2rel_0123

或任何其他智能食谱? (不,我们不会重命名 50 多个表中的所有内容)

类似的线程位于 https://stackoverflow。 com/questions/194945/migration-from-postgresql-to-oracle

感谢您的任何想法或反馈
斯文

we are using PostgreSQL (and we are happy with it!), but due to customer policies we need to run our app on Oracle. Unfortunately our ERD is full of identifier (column names and relationship names) with more than 30 char length (and even Oracle 11g in the 21 st century still cannot digest that, ORA-00972 !).

Do you know any tools that can help to rename automatically long names ?
eg my_very_long_rel_from_table1_to_table2 to rel_0123

Or any other smart recipes ? (No, we not gonna rename everything in 50+ tables)

Similar thread at https://stackoverflow.com/questions/194945/migrating-from-postgresql-to-oracle

Thanks for any ideas or feedback
Sven

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

稀香 2024-12-16 17:23:49

优秀。然后是 sed。

列出 Postgres 模式中的所有标识符(例如来自 information_schema)。粘贴到 A 列中的 Excel。复制到 B 列。创建一个 C 列,它将显示 B 中的标识符名称长度。按 C 排序。手动缩短 B 中长度超过 30 的标识符,直到没有(我建议不要这样做)自动,因为它会使您的数据库变得模糊)。创建 D 列,其中 D1 为:concatenate("sed 's/",A1,"/",B1,"/g'")。

将 D 列复制到文件“change_columns.sh”。通过它过滤 Postgres 架构。通过它过滤你的客户端程序源。

引入关系名称不超过30个字符的政策。例如,使用 cron 中的架构每日检查来强制执行。

丑得要命。

Excel. And then sed.

List all identifiers in schema from Postgres (for example from information_schema). Paste to Excel in column A. Copy to column B. Create a column C which will show identifier name lengths in B. Sort by C. Manually shorten identifiers in B which are longer than 30 until there's none (I'd suggest not doing it automatically, as it would make your database obfuscated). Create column D where D1 would be: concatenate("sed 's/",A1,"/",B1,"/g'").

Copy column D to file "change_columns.sh". Filter Postgres schema through it. Filter your client program source through it.

Introduce a policy that relation names are not longer than 30 characters. Enforce it using for example daily checks of schema in cron.

Ugly as hell.

夏日落 2024-12-16 17:23:49

我使用 perl 并指向 pg_dump 文件。对于名称缩写,我有类似的东西:

sub shorten_name {
    my $name = shift;
    return $name if (length $name <= 30);

    my @abbreviations = ('calculation,calc', 'measure,meas', 'point,pt', ...); 

    my $new_name = $name;
    foreach my $abbr (@abbreviations) {
        my ($f, $r) = split ',', $abbr;
        $new_name =~ s/$f/$r/g;
        last if (length($new_name) <= 30);
    }

    if (length $new_name > 30) {
        warn "Unable to shorten $name\n";
    }
    return $new_name;
}

我使用数组与哈希,因为我想控制应用缩写的顺序(某些缩写比其他缩写更可取)。

这是一个非常丑陋的脚本,但它以可重复的方式完成了工作。

其他需要注意的事项包括数据类型映射(尤其是 Oracle 不支持的数据类型)、域、更新外键、触发器等。

I used perl and pointed at a pg_dump file. For the name shortening I had something like:

sub shorten_name {
    my $name = shift;
    return $name if (length $name <= 30);

    my @abbreviations = ('calculation,calc', 'measure,meas', 'point,pt', ...); 

    my $new_name = $name;
    foreach my $abbr (@abbreviations) {
        my ($f, $r) = split ',', $abbr;
        $new_name =~ s/$f/$r/g;
        last if (length($new_name) <= 30);
    }

    if (length $new_name > 30) {
        warn "Unable to shorten $name\n";
    }
    return $new_name;
}

I used an array vs a hash as I wanted to control the order that the shortenings were applied (some abbreviations were much more desirable than others).

'twas a very ugly script but it got the job done in a repeatable fashion.

Other things to look out for are the datatype mappings (especially for data types that oracle doesn't support), domains, on update foreign keys, triggers, etc.

往日 2024-12-16 17:23:49

奇怪的是,我可能正是你所需要的,尽管答案可能令人惊讶。

我们的PLSQL Obfuscator通常用于打乱PLSQL代码以使其难以理解。

它所做的事情之一是重命名标识符。通常,它会选择“随机”名称
人们很难手动可靠地阅读或复制。
但是,有一个功能可以让您精确控制名称的映射方式。
(全部在文档中)
您可以使用它来轻松实现您想要的效果。

它对标识符名称的长度并不挑剔,所以你天真的转换
具有长标识符的 PLSQL 不会打扰它。重命名后,你会想要
确保名称都适当简短。

Weirdly enough I may have just what you need, although the answer is likely a surprise.

Our PLSQL Obfuscator is normally used to scramble PLSQL code to make it hard to understand.

One of things it does is rename identifiers. Normally, it picks "random" names
that are very hard for people to read or copy reliably manually.
However, there's a feature that allows you to control exactly how names are mapped.
(Its all in the docs)
And you could use that to achieve the effect your want pretty easily.

It isn't cranky about the lenght of identifier names, so your naive conversion
to PLSQL with long identifiers won't bother it. After renaming, you'd want
to make sure the names were all appropriately short.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文