Thread: Using types in an inappropriate way causes crash of backend

Using types in an inappropriate way causes crash of backend

From
pgsql-bugs@postgresql.org
Date:
Boris Boehlen (boris@i3.informatik.rwth-aachen.de) reports a bug with a severity of 1
The lower the number the more severe it is.

Short Description
Using types in an inappropriate way causes crash of backend

Long Description
I tried to create a type to achieve the same as the "CREATE DOMAIN"
command of SQL2. After declaring a type `f' which should be the same
as `int4' I created table using this type. When tried to insert a value
into the table I got the following error:

  ERROR:  Attribute 'a' is of type 'f' but expression is of type 'int4'
    You will need to rewrite or cast the expression

Then I tried the next insert statement and the backend crashed.

BTW: How can I achieve the same as using "CREATE DOMAIN" without
extending PSQL?


Sample Code
create type f (input = int4in, output=int4out, internallength=4);
create table z (a f);
insert into z values(1);
insert into z values('1');

No file was uploaded with this report

Re: Using types in an inappropriate way causes crash of backend

From
Tom Lane
Date:
pgsql-bugs@postgresql.org writes:
> create type f (input = int4in, output=int4out, internallength=4);

You forgot to specify PASSEDBYVALUE.

            regards, tom lane

Re: Using types in an inappropriate way causes crash of backend

From
Thomas Lockhart
Date:
>   ERROR:  Attribute 'a' is of type 'f' but expression is of type 'int4'
>         You will need to rewrite or cast the expression
> Then I tried the next insert statement and the backend crashed.
...
> Sample Code
> create type f (input = int4in, output=int4out, internallength=4);
> create table z (a f);
> insert into z values(1);
> insert into z values('1');

The first case threw an error because you did not declare any conversion
functions between int4 and your type "f". You will need to provide a
noop, which can be as simple as (ymmv; I'm doing this from scratch):

create function f(int4) returns f as ...

where the conversion function must be, afaik, compiled code (our SQL
embedded language is too smart to let you pass it through unchanged).

Otherwise, you need to use the second, quoted, style for data entry.

                    - Thomas