Re: ALTER OBJECT any_name SET SCHEMA name

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Dimitri Fontaine <dimitri(at)2ndquadrant(dot)fr>
Cc: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: ALTER OBJECT any_name SET SCHEMA name
Date: 2010-11-04 15:48:12
Message-ID: 1288881965-sup-8048@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Excerpts from Dimitri Fontaine's message of jue nov 04 11:37:37 -0300 2010:
> Alvaro Herrera <alvherre(at)commandprompt(dot)com> writes:
> >> /* check for duplicate name (more friendly than unique-index failure) */
> >> if (SearchSysCacheExists2(TYPENAMENSP,
> >> CStringGetDatum(name),
> >> ObjectIdGetDatum(nspOid)))
> >
> > Hmm, this check is wrong anyway, because you're looking in the pg_type
> > syscache for objects from an arbitrary catalog. That needs to be fixed
> > somehow, but perhaps it needs to be handled by the callers, not in this
> > routine. Otherwise you're going to need to pass the syscache ID, as
> > well as Datums identifying the object, and the number of Datums.
>
> How embarrassing. I wonder why this works, too:
>
> dim=# alter operator utils.@>(utils.ltree, utils.ltree) set schema public;
> ALTER OPERATOR

Well, I guess the operator doesn't exist in the pg_type syscache, so it
doesn't ereport(ERROR).

> Well, I'll go fix as you say, putting the check back into the
> callers. That won't help a bit with the code duplication feeling we have
> when reading the patch, though. Any idea on this front?

I'm not really sure about the code duplication bits. There are plenty
of things you cannot factor into common routines because of the need to
handle different GETSTRUCT args, different number of syscache arguments,
etc. The ALTER OWNER implementation is already "duplicated" for each
database object. Your patch is already reducing duplication by moving
some common checks into namespace.c.

If there are more things that you could do by specifying a syscache ID
and datums to be passed to it, perhaps it would make sense to use them
as parameters to a function that does the whole bunch together. This
probably doesn't belong into namespace.c though.

--
Álvaro Herrera <alvherre(at)commandprompt(dot)com>
The PostgreSQL Company - Command Prompt, Inc.
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2010-11-04 15:50:51 Re: ALTER OBJECT any_name SET SCHEMA name
Previous Message Robert Haas 2010-11-04 15:33:22 Re: ALTER OBJECT any_name SET SCHEMA name