我想知道为什么两个 varchar 的串联会给我结果中的文本类型。
select 'Plural'::varchar || 'sight'::varchar;
键入我在 PGAdmin3(服务器:9.4)输出中看到的串联“文本”。
最佳答案
test=> \doS ||
List of operators
┌────────────┬──────┬───────────────┬────────────────┬─────────────┬─────────────────────────────────────┐
│ Schema │ Name │ Left arg type │ Right arg type │ Result type │ Description │
├────────────┼──────┼───────────────┼────────────────┼─────────────┼─────────────────────────────────────┤
│ pg_catalog │ || │ anyarray │ anyarray │ anyarray │ concatenate │
│ pg_catalog │ || │ anyarray │ anyelement │ anyarray │ append element onto end of array │
│ pg_catalog │ || │ anyelement │ anyarray │ anyarray │ prepend element onto front of array │
│ pg_catalog │ || │ anynonarray │ text │ text │ concatenate │
│ pg_catalog │ || │ bit varying │ bit varying │ bit varying │ concatenate │
│ pg_catalog │ || │ bytea │ bytea │ bytea │ concatenate │
│ pg_catalog │ || │ jsonb │ jsonb │ jsonb │ concatenate │
│ pg_catalog │ || │ text │ anynonarray │ text │ concatenate │
│ pg_catalog │ || │ text │ text │ text │ concatenate │
│ pg_catalog │ || │ tsquery │ tsquery │ tsquery │ OR-concatenate │
│ pg_catalog │ || │ tsvector │ tsvector │ tsvector │ concatenate │
└────────────┴──────┴───────────────┴────────────────┴─────────────┴─────────────────────────────────────┘
(11 rows)
varchar
没有||
运算符。发生的事情是 PostgreSQL 将 varchar
转换为 text
(这是此类型类别中的首选类型)。
操作的结果也将是 text
。
关于Postgresql 9.6 varchar 的串联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41957862/