Redshift varchar 太窄
Redshift varchar too narrow
我有一个 table,我用来自文件的制表符分隔数据填充,这些文件的编码似乎不完全是 utf-8,如下所示:
CREATE TABLE tab (
url varchar(2000),
...
);
COPY tab
FROM 's3://input.tsv'
复制完成后我运行
SELECT
MAX(LEN(url))
FROM tab
其中 returns 1525
。我想,因为我在浪费 space,我还不如使用 varchar(2000)
而不是 varchar(1525)
将列的大小调整近四分之一。但是重做 COPY
或设置新的 table 并插入已导入的数据都不起作用。在这两种情况下,我都得到
error: Value too long for character type
为什么该列不包含这些值?
您的文件可能是 multi-byte 格式。
The LEN function returns an integer indicating the number of characters in the input string. The LEN function returns the actual number of characters in multi-byte strings, not the number of bytes. For example, a VARCHAR(12) column is required to store three four-byte Chinese characters. The LEN function will return 3 for that same string.
由于 Amazon Redshift 使用的压缩方法,VARCHAR 的额外大小不会浪费磁盘 space,但在读取块时会浪费 in-memory 缓冲区 space从磁盘解压到内存中。
我有一个 table,我用来自文件的制表符分隔数据填充,这些文件的编码似乎不完全是 utf-8,如下所示:
CREATE TABLE tab (
url varchar(2000),
...
);
COPY tab
FROM 's3://input.tsv'
复制完成后我运行
SELECT
MAX(LEN(url))
FROM tab
其中 returns 1525
。我想,因为我在浪费 space,我还不如使用 varchar(2000)
而不是 varchar(1525)
将列的大小调整近四分之一。但是重做 COPY
或设置新的 table 并插入已导入的数据都不起作用。在这两种情况下,我都得到
error: Value too long for character type
为什么该列不包含这些值?
您的文件可能是 multi-byte 格式。
The LEN function returns an integer indicating the number of characters in the input string. The LEN function returns the actual number of characters in multi-byte strings, not the number of bytes. For example, a VARCHAR(12) column is required to store three four-byte Chinese characters. The LEN function will return 3 for that same string.
由于 Amazon Redshift 使用的压缩方法,VARCHAR 的额外大小不会浪费磁盘 space,但在读取块时会浪费 in-memory 缓冲区 space从磁盘解压到内存中。