Implicit shell type creation, little fixes

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Implicit shell type creation, little fixes
Date: 2026-08-19 09:52:14
Message-ID: de673feb-41b4-4685-b24b-6408b95e58ab@iki.fi
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I noticed this with the old style implicit shell type creation:

postgres=# create function blah(text, text, text) returns bogus_type[]
immutable strict language internal as 'int8out';
NOTICE: type "bogus_type[]" is not yet defined
DETAIL: Creating a shell type definition.
CREATE FUNCTION

Surely we shouldn't create a shell type when the array syntax was used?
This path is for old scripts that created the I/O functions before the
type definition, and you wouldn't specify I/O functions for an array
like this.

If you then repeat the command, after the shell type's been created, you
unsurprisingly get this:

postgres=# create function blah(text, text, text) returns bogus_type[]
strict language internal as 'int8out';
NOTICE: type "bogus_type[]" is not yet defined
DETAIL: Creating a shell type definition.
ERROR: duplicate key value violates unique constraint
"pg_type_typname_nsp_index"
DETAIL: Key (typname, typnamespace)=(bogus_type, 2200) already exists.

I propose the attached to fix that. It also changes the error message
you get if you specify a typmod and the type doesn't exist. Currently on
master:

postgres=# create function blah(text, text, text) returns
bogus_type(100) strict language internal as 'int8out';
ERROR: type modifier cannot be specified for shell type "bogus_type"

And with the patch:

postgres=# create function blah(text, text, text) returns
bogus_type(100) strict language internal as 'int8out';
ERROR: type "bogus_type" does not exist

I think "type does not exist" is better, it's unlikely that the user
really intended to create a shell type.

We could narrow down further the criteria for shell type creation. It's
really only needed for creating the input function, so we could check
that the signature looks like an input function. For example, the above
'blah' function takes text args, so it's surely not an input function
and could be rejected on those grounds. But I didn't include that in
this patch yet.

- Heikki

P.S. I know the 'int8out' internal function is wouldn't work for the
definitions in the above examples anyway, please ignore that

Attachment Content-Type Size
0001-Don-t-create-a-shell-type-for-function-returning-an-.patch text/x-patch 12.4 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message shveta malik 2026-08-19 09:52:46 Re: [PATCH] Preserve replication origin OIDs in pg_upgrade
Previous Message Daniel Gustafsson 2026-08-19 09:47:30 Re: Python/pytest test framework take two