Postgresql 9.6 varchar 的串联

标签 postgresql postgresql-9.4

我想知道为什么两个 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/

相关文章:

java - 如何使用制表符格式化输出以使表格看起来清晰

postgresql - Postgres 从 jsonb 数组中提取值

postgresql - 如何在 Postgresql 中创建具有初始大小的表空间?

sql - 从 SELECT 查询结果中复制? (在 postgresql 中)

python - psycopg creata 数据库失败,语法错误

postgresql - PostgresQL。与在 WHERE 子句中显式定义整个时间戳相比,将时间戳转换为日期的区别

java - 使用 Postgres 和 Hibernate(Grails) 选择语句后在事务中空闲

sql - 具有相同外键唯一约束的Postgresql多个表

sql - Postgres函数在两个表中插入多条记录

postgresql - 将 `jsonb_array_elements` 的多行结果扩展到 PL/pgSQL 过程中的 tsvector