
Why when i create domain like :

CREATE DOMAIN alias_to_int AS INT;

and then function like :

CREATE FUNCTION func() RETURNS alist_to_int AS ' select 2::int; ' LANGUAGE
SQL;

and pg can not convert int to aliast_to_int, so i need to create cast for
all this same types ?


Sun, 17 Aug 2003 18:34:36 +0200 (CEST)
ivan <iv@psycho.pl>
DOMAIN NEED CAST ?
On Sun, 2003-08-17 at 12:34, ivan wrote:
> Why when i create domain like :
> 
> CREATE DOMAIN alias_to_int AS INT;
> 
> and then function like :
> 
> CREATE FUNCTION func() RETURNS alist_to_int AS ' select 2::int; ' LANGUAGE
> SQL;
> 
> and pg can not convert int to aliast_to_int, so i need to create cast for
> all this same types ?

PostgreSQL will not cast your function return results for you.

rbt=# create function func() returns integer as 'select 2::int2'
language sql;
ERROR:  return type mismatch in function: declared to return integer,
returns smallint
Sun, 17 Aug 2003 12:48:02 -0400
Rod Taylor <rbt@rbt.ca>
Re: DOMAIN NEED CAST ?

but in real alias_to_int is equal to int, only with other name;
its should be like typedef from c/c++ ?

On Sun, 17 Aug 2003, Rod Taylor wrote:

> On Sun, 2003-08-17 at 12:34, ivan wrote:
> > Why when i create domain like :
> >
> > CREATE DOMAIN alias_to_int AS INT;
> >
> > and then function like :
> >
> > CREATE FUNCTION func() RETURNS alist_to_int AS ' select 2::int; ' LANGUAGE
> > SQL;
> >
> > and pg can not convert int to aliast_to_int, so i need to create cast for
> > all this same types ?
>
> PostgreSQL will not cast your function return results for you.
>
> rbt=# create function func() returns integer as 'select 2::int2'
> language sql;
> ERROR:  return type mismatch in function: declared to return integer,
> returns smallint
>
>
>

Sun, 17 Aug 2003 20:30:13 +0200 (CEST)
ivan <iv@psycho.pl>
Re: DOMAIN NEED CAST ?
On Sun, 2003-08-17 at 14:30, ivan wrote:
> but in real alias_to_int is equal to int, only with other name;
> its should be like typedef from c/c++ ?

Not necessarily.

CREATE DOMAIN alias_to_int AS INT CHECK(VALUE BETWEEN 1 AND 4);

The above is very different than plain old integer.
Sun, 17 Aug 2003 14:58:48 -0400
Rod Taylor <rbt@rbt.ca>
Re: DOMAIN NEED CAST ?


ok, but in this use, but when i need to create datatype,
which i use in other tables (to be sure that always is this same)
i need to always writing casting to convert int to int ?

On Sun, 17 Aug 2003, Rod Taylor wrote:

> On Sun, 2003-08-17 at 14:30, ivan wrote:
> > but in real alias_to_int is equal to int, only with other name;
> > its should be like typedef from c/c++ ?
>
> Not necessarily.
>
> CREATE DOMAIN alias_to_int AS INT CHECK(VALUE BETWEEN 1 AND 4);
>
> The above is very different than plain old integer.
>

Mon, 18 Aug 2003 20:14:27 +0200 (CEST)
ivan <iv@psycho.pl>
Re: DOMAIN NEED CAST ?