我想使用concat函数或||操作符将文本数据插入到Postgres bytea列中。我收到一个错误
column "name" is of type bytea but expression is of type textcreate table test(
name bytea
);
insert into test(name) values(concat('abac-' , 'test123'));
insert into test(name) values('aa' || 'bb');我在存储过程中执行insert。如果想要添加参数,如
(concat('abac-' , row.name , 'test123'));我该怎么做呢?
发布于 2021-09-22 02:55:36
在连接这些值之后执行类型转换:
INSERT INTO test (name)
VALUES (CAST('abac-' || row.name || 'test123' AS bytea));注意:||和concat之间的区别在于它们在处理空值时的行为方式。
发布于 2021-09-22 01:37:51
您需要将这两个字符串都转换为bytea,例如:
insert into test(name) values('aa'::bytea || 'bb'::bytea);https://stackoverflow.com/questions/69277119
复制相似问题