SQLite 和 PostgreSql 长文本
有谁知道如何将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
对于 PostgreSQL,请参阅文档此处(例如,
ALTER TABLE my_table ALTER COLUMN my_col text
)。SQLite 文档指出
我想更改列的数据类型超出了范围。可能为了支持这一点,您需要执行
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
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 byDROP TABLE ...
and then create the table and runINSERT INTO ... SELECT * FROM ...
在 SQLite 中声明
LONGTEXT
列是没有意义的。所有包含TEXT
或CHAR
或CLOB
的类型名称都是等效的。There's no point in declaring a
LONGTEXT
column in SQLite. All type names withTEXT
orCHAR
orCLOB
in them are equivalent.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)
我不知道您对 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.