views:

52

answers:

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);
A: 

You have to tell PostgreSQL how to cast, CREATE CAST

Frank Heikens
So I need to create a function to do the cast for me? How exactly would I go about this?
nix
A: 

Well, to create a cast you need a function that takes a value of one type as your input and outputs the type you wish to cast to (in this case "ID" - which I would name a little more verbose if I were you). What type do you want to cast from?

Realize without messing with all that, you should be able to use your type according to this page.

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

rfusca