错误:找不到从未知到文本的转换功能 [英] ERROR: failed to find conversion function from unknown to text
问题描述
在PostgreSQL上有一个错误,它在我的select语句之一中给出。我在网上搜索了一个答案,然后空手而归。另一个问题给出的答案不适合我的问题。
There is an error on PostgreSQL that it gives on one of my select statements. I searched the web for an answer and came out empty handed. The answer given in another question did not suit my problem.
ERROR: failed to find conversion function from unknown to text
********** Error **********
ERROR: failed to find conversion function from unknown to text
SQL state: XX000
我的查询看起来像这样:
My query looks something like this:
Select *
from (select 'string' as Rowname, Data
From table)
Union all
(select 'string2' as Rowname, Data
From table)
这样做的目的是指定该行在哪一行点。字符串是行的名称。这是我想要的输出:
The point of doing this is to specify what the row is at one point. The string being the name of the row. Here is my desired output:
Rowname Data
string 53
string2 87
有什么方法可以解决此错误?
Any possible way to fix this error?
推荐答案
您的语句有两个问题。但是错误消息表明您需要 显式强制转换 以声明字符串文字'string'
的(至今未知)数据类型:
Your statement has a couple of problems. But the error message implies that you need an explicit cast to declare the (yet unknown) data type of the string literal 'string'
:
SELECT text 'string' AS rowname, data FROM tbl1
UNION ALL
SELECT 'string2', data FROM tbl2
足以投射一个<$ c $的 SELECT
个c> UNION 查询。通常是第一个,其中还要确定列名称。随后的具有未知类型的 SELECT
列表将排在一行。
It's enough to cast in one SELECT
of a UNION
query. Typically the first one, where column names are also decided. Subsequent SELECT
lists with unknown types will fall in line.
在其他情况下(例如 INSERT
的> VALUES 子句)Postgres从目标列导出数据类型,并尝试自动强制转换为正确的类型。
In other contexts (like the VALUES
clause attached to an INSERT
) Postgres derives data types from target columns and tries to coerce to the right type automatically.
这篇关于错误:找不到从未知到文本的转换功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!