2

I have created a data type called id which consists of two text values:

id(text, text)

I now need to cast values to this data type before they are inserted into my table. How would I go about doing this?

I created the type as follows:

CREATE TYPE ID AS(id text, source text);
4

2 回答 2

4

好吧,要创建一个转换,您需要一个函数,该函数将一个类型的值作为您的输入并输出您希望转换为的类型(在本例中为“ID” - 如果我是你,我会更详细地命名它) . 你想从什么类型投射?

意识到不搞乱这一切,你应该可以根据这个页面使用你的类型。

只是.. SELECT ROW('foo','bar')::ID ;

于 2010-07-09T15:26:38.440 回答
2

你必须告诉 PostgreSQL 如何投射,CREATE CAST

于 2010-07-09T07:02:41.213 回答