Thread: [PATCH] WIP: Create shell-types explicitly

[PATCH] WIP: Create shell-types explicitly

From
Martijn van Oosterhout
Date:
[Please CC any replies, thanks]

Persuant to the recent discussion, here is a patch to allow users to
create shell types by using the symtax:

CREATE TYPE foo;

It was actually much easier than I thought given that normal type
creation creates a shell type just before creating the real type. This
means it works just by stopping after creating the shell type before
creating the real type. This also means that issuing a "CREATE TYPE
foo;" on an already existing type succeeds without doing anything, just
like structure declarations in C.

Unfortuntly there are some minor issues not quite considered when this
was first brought up. Primarily this:

postgres=# create type text;
CREATE TYPE
postgres=# select * from pg_type where typname = 'text';
 typname | typnamespace | typowner | typlen | typbyval | typtype | typisdefined | typdelim | typrelid | typelem |
typinput| typoutput | typreceive | typsend  | typanalyze | typalign | typstorage | typnotnull | typbasetype | typtypmod
|typndims | typdefaultbin | typdefault  

---------+--------------+----------+--------+----------+---------+--------------+----------+----------+---------+----------+-----------+------------+----------+------------+----------+------------+------------+-------------+-----------+----------+---------------+------------
 text    |           11 |       10 |     -1 | f        | b       | t            | ,        |        0 |       0 |
textin  | textout   | textrecv   | textsend | -          | i        | x          | f          |           0 |        -1
|       0 |               |  
 text    |         2200 |       10 |      4 | t        | p       | f            | ,        |        0 |       0 |
shell_in| shell_out | -          | -        | -          | i        | p          | f          |           0 |        -1
|       0 |               |  
(2 rows)

postgres=# drop type text;
ERROR:  cannot drop type text because it is required by the database system
postgres=# drop type public.text;
DROP TYPE

The first line creates public.text, but the drop tries to delete
pg_catalog.text. I'm not sure which we should make smarter, the create
or the drop, or whether just the error messages need to be made much
clearer as to what's going on.

Other points:
- Changed the shell create function to create a type with the same
parameters as a pseudotype. This should address Tom's issue with code
not paying attention to the fact the type is not complete yet.

- Created two functions shell_in and shell_out persuant to making shell
types look like pseudo types. I however didn't actually create a
pseudotype "shell" so shell_in actually returns "opaque". Do people
have a problem with this?

- I still think it would be useful to require people to create the
shell type and the complete type within the same transaction, if only
to prevent people filling up catalog with useless entries. Shell types
can be dropped as normal, but still...

- Includes documentation updates. Does not include regression tests,
yet.

Comments?

http://svana.org/kleptog/pgsql/shell.diff
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Attachment

Re: [PATCH] WIP: Create shell-types explicitly

From
Tom Lane
Date:
Martijn van Oosterhout <kleptog@svana.org> writes:
> The first line creates public.text, but the drop tries to delete
> pg_catalog.text.

This is not particularly specific to (or relevant to) shell types.

            regards, tom lane

Re: [PATCH] WIP: Create shell-types explicitly

From
Martijn van Oosterhout
Date:
On Mon, Feb 20, 2006 at 10:13:39AM -0500, Tom Lane wrote:
> Martijn van Oosterhout <kleptog@svana.org> writes:
> > The first line creates public.text, but the drop tries to delete
> > pg_catalog.text.
>
> This is not particularly specific to (or relevant to) shell types.

So this is not a show stopper and not something we're particularly
concerned about?

Thanks,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Attachment

Re: [PATCH] WIP: Create shell-types explicitly

From
Tom Lane
Date:
Martijn van Oosterhout <kleptog@svana.org> writes:
> On Mon, Feb 20, 2006 at 10:13:39AM -0500, Tom Lane wrote:
>> Martijn van Oosterhout <kleptog@svana.org> writes:
>>> The first line creates public.text, but the drop tries to delete
>>> pg_catalog.text.
>>
>> This is not particularly specific to (or relevant to) shell types.

> So this is not a show stopper and not something we're particularly
> concerned about?

I'm not concerned about it.  If you're using the default search path,
you'd see the same behavior anytime you created any object with the same
name as a pg_catalog object.  It's been like that since 7.3, and I don't
recall seeing any complaints from users (as distinct from people trying
to break things ;-)) so I'm not very worried.

            regards, tom lane