SQLite 和 PostgreSql 长文本

发布于 2024-08-31 11:38:13 字数 271 浏览 2 评论 0原文

有谁知道如何将 SQLite 和 PostgreSQL 中的列更改为 LONGTEXT?

我已经在 MySQL 中成功做到了这一点: “ALTER TABLE 项目修改描述 LONGTEXT;”

但这个子句似乎在 SQLite 上不起作用。我努力寻找有关 PostgreSQL 的文档,但那个网站的格式确实让人恶心。 SQLite 的网站更好,但我发现唯一相关的命令 alter table 似乎根本不支持更改列数据类型。 (事实上​​,它甚至不允许更改列名称!!!)

谢谢大家!

Does anyone know how to change a column in SQLite and PostgreSQL to LONGTEXT?

I have done so in MySQL successfully with:
"ALTER TABLE projects MODIFY description LONGTEXT;"

But this clause doesn't seem to work on SQLite. I tried hard to find documentation on PostgreSQL, but that site's format really makes people puke. SQLite's website is better but the only command I find relevant, alter table, doesn't seem to support changing column data type at all. ( infact, it doesn't even allow changing column name!!!)

Thanks all!

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

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

发布评论

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

评论(4

梦毁影碎の 2024-09-07 11:38:13

对于 PostgreSQL,请参阅文档此处(例如, ALTER TABLE my_table ALTER COLUMN my_col text)。

SQLite 文档指出

SQLite 支持 ALTER TABLE 的有限子集。 SQLite 中的 ALTER TABLE 命令允许用户重命名表或向现有表添加新列。无法重命名列、删除列或添加或删除表中的约束。

我想更改列的数据类型超出了范围。可能为了支持这一点,您需要执行SELECT * INTO ...,然后执行DROP TABLE ...,然后创建表并运行INSERT INTO ...从...中选择*

For PostgreSQL, see the doc here (e.g., ALTER TABLE my_table ALTER COLUMN my_col text).

The SQLite doc states

SQLite supports a limited subset of ALTER TABLE. The ALTER TABLE command in SQLite allows the user to rename a table or to add a new column to an existing table. It is not possible to rename a column, remove a column, or add or remove constraints from a table.

And I suppose changing the datatype of the column is out of scope. Probably to support this, you will need to do a SELECT * INTO ... followed by DROP TABLE ... and then create the table and run INSERT INTO ... SELECT * FROM ...

策马西风 2024-09-07 11:38:13

在 SQLite 中声明 LONGTEXT 列是没有意义的。所有包含 TEXTCHARCLOB 的类型名称都是等效的。

There's no point in declaring a LONGTEXT column in SQLite. All type names with TEXT or CHAR or CLOB in them are equivalent.

孤蝉 2024-09-07 11:38:13

AFAIK,PostgreSQL 对 blob 没有限制,所以不用担心。

显然,SQLite3 不关心这种情况下的列类型(即 TEXT 与 LONGTEXT 相同)

AFAIK, PostgreSQL does not have a limit on blobs, so don't worry.

SQLite3, apparently, doesn't care about the column type in this case (i.e. TEXT is the same as LONGTEXT)

守不住的情 2024-09-07 11:38:13

我不知道您对 Postresql 文档 有什么问题,它是海事组织相当不错。

要更改列数据类型,此处是语法。

Postgres 通过 文本数据类型

I don't know what problem you have with Postresql documentation, it's quite good IMO.

To change a column datatype, here is the syntax.

Postgres supports arbitrary long strings (well, up to 2 GB or so) with the TEXT datatype.

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