Thread: BUG #4056: problem creating function with domain argument

BUG #4056: problem creating function with domain argument

From
"eric melbardis"
Date:
The following bug has been logged online:

Bug reference:      4056
Logged by:          eric melbardis
Email address:      eric.melbardis@netkitsolutions.com
PostgreSQL version: 8.3.1
Operating system:   windows xp sp 2
Description:        problem creating function with domain argument
Details:

hi when i execute the following script using pgadmin query tool:

--------------------------------

CREATE DOMAIN "dt_0" AS varchar(32)
    NULL;

CREATE DOMAIN "dt_1" AS varchar
    NULL;



CREATE FUNCTION "x1" (IN name dt_0, IN description dt_1)
RETURNS integer
AS $$
SELECT 0;
$$
LANGUAGE SQL
IMMUTABLE
RETURNS NULL ON NULL INPUT;


---------------------------


when i look at the function definition using pgadmin it looks like this:

-- Function: x1(dt_0(36), dt_1)

-- DROP FUNCTION x1(dt_0(36), dt_1);

CREATE OR REPLACE FUNCTION x1("name" dt_0(36), description dt_1)
  RETURNS integer AS
$BODY$
SELECT 0;
$BODY$
  LANGUAGE 'sql' IMMUTABLE STRICT
  COST 100;
ALTER FUNCTION x1(dt_0(36), dt_1) OWNER TO postgres;

--------------------------

if i try to delete it: i get:

an error has occured: tyep modifier is not allowed for type "dt_0"

why is the (36) there????


regards

Re: BUG #4056: problem creating function with domain argument

From
Tom Lane
Date:
"eric melbardis" <eric.melbardis@netkitsolutions.com> writes:
> Description:        problem creating function with domain argument

AFAICT this example works fine in psql.  You need to take it up
on the pgAdmin mailing list.  It looks to me like pgAdmin is mistakenly
thinking that a domain has type modifiers.

            regards, tom lane

Re: BUG #4056: problem creating function with domain argument

From
"Dave Page"
Date:
On Tue, Mar 25, 2008 at 5:37 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> "eric melbardis" <eric.melbardis@netkitsolutions.com> writes:
>  > Description:        problem creating function with domain argument
>
>  AFAICT this example works fine in psql.  You need to take it up
>  on the pgAdmin mailing list.  It looks to me like pgAdmin is mistakenly
>  thinking that a domain has type modifiers.

pgAdmin is using format_type() with a query like:

postgres=# SELECT oid, format_type(oid, typtypmod) AS typname FROM
pg_type where oid = 'dt_0'::regtype;
  oid  | typname
-------+----------
 35130 | dt_0(36)
(1 row)

I would expect it to format the type appropriately.

--
Dave Page
EnterpriseDB UK Ltd: http://www.enterprisedb.com
PostgreSQL UK 2008 Conference: http://www.postgresql.org.uk

Re: BUG #4056: problem creating function with domain argument

From
Tom Lane
Date:
"Dave Page" <dpage@pgadmin.org> writes:
> On Tue, Mar 25, 2008 at 5:37 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> ... It looks to me like pgAdmin is mistakenly
>> thinking that a domain has type modifiers.

> pgAdmin is using format_type() with a query like:

> postgres=# SELECT oid, format_type(oid, typtypmod) AS typname FROM
> pg_type where oid = 'dt_0'::regtype;
>   oid  | typname
> -------+----------
>  35130 | dt_0(36)
> (1 row)

> I would expect it to format the type appropriately.

No, the above is entirely wrong.  typtypmod is the typmod that goes with
the domain's base type, not with the domain itself.  You got away with
this mistaken code before 8.3 because format_type just silently ignored
its typmod argument for all but a very small number of types.  But now
the default behavior is to print the typmod.

When looking at a domain type, format_type(typbasetype,typtypmod)
would be a sane thing to do.  But that typmod isn't to be attached
to the domain itself.

            regards, tom lane

Re: BUG #4056: problem creating function with domain argument

From
"Eric P. Melbardis"
Date:
Hi

Just a question..

The type was declared as follows:

CREATE DOMAIN "dt_0" AS varchar(32)
    NULL;

So why does the query respond with 36?

Regards

-----Original Message-----
From: Tom Lane [mailto:tgl@sss.pgh.pa.us]=20
Sent: Thursday, March 27, 2008 10:53 AM
To: Dave Page
Cc: Eric P. Melbardis; pgsql-bugs@postgresql.org
Subject: Re: [BUGS] BUG #4056: problem creating function with domain
argument=20

"Dave Page" <dpage@pgadmin.org> writes:
> On Tue, Mar 25, 2008 at 5:37 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> ... It looks to me like pgAdmin is mistakenly
>> thinking that a domain has type modifiers.

> pgAdmin is using format_type() with a query like:

> postgres=3D# SELECT oid, format_type(oid, typtypmod) AS typname FROM
> pg_type where oid =3D 'dt_0'::regtype;
>   oid  | typname
> -------+----------
>  35130 | dt_0(36)
> (1 row)

> I would expect it to format the type appropriately.

No, the above is entirely wrong.  typtypmod is the typmod that goes with
the domain's base type, not with the domain itself.  You got away with
this mistaken code before 8.3 because format_type just silently ignored
its typmod argument for all but a very small number of types.  But now
the default behavior is to print the typmod.

When looking at a domain type, format_type(typbasetype,typtypmod)
would be a sane thing to do.  But that typmod isn't to be attached
to the domain itself.

            regards, tom lane

Re: BUG #4056: problem creating function with domain argument

From
"Dave Page"
Date:
On Thu, Mar 27, 2008 at 5:52 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

>  No, the above is entirely wrong.  typtypmod is the typmod that goes with
>  the domain's base type, not with the domain itself.  You got away with
>  this mistaken code before 8.3 because format_type just silently ignored
>  its typmod argument for all but a very small number of types.  But now
>  the default behavior is to print the typmod.

Ahh, gotcha. Fixed in pgAdmin, thanks.

--
Dave Page
EnterpriseDB UK Ltd: http://www.enterprisedb.com
PostgreSQL UK 2008 Conference: http://www.postgresql.org.uk