[PATCH] WIP: Create shell-types explicitly - Mailing list pgsql-patches

From Martijn van Oosterhout
Subject [PATCH] WIP: Create shell-types explicitly
Date
Msg-id 20060220115724.GC12673@svana.org
Whole thread Raw
Responses Re: [PATCH] WIP: Create shell-types explicitly  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-patches
[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

pgsql-patches by date:

Previous
From: daveg
Date:
Subject: Re: plpython tracebacks
Next
From: "Marko Kreen"
Date:
Subject: Re: pgcrypto: fix memory leak in openssl.c