BUG #14649: Function Namespace Resolution Bug

From: jeremy(at)cowgar(dot)com
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #14649: Function Namespace Resolution Bug
Date: 2017-05-12 17:40:59
Message-ID: 20170512174059.1791.21888@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 14649
Logged by: Jeremy Cowgar
Email address: jeremy(at)cowgar(dot)com
PostgreSQL version: 9.6.1
Operating system: Debian
Description:

We ran across an issue restoring our database recently and have tracked it
down. The following SQL exposes the bug. It appears to deal with a confusion
of schema namespaces, thus the "create schema g” line is vital to expose
this problem.

In short, when a CHECK on a column in a different schema references a
function in public that references another function in public implicitly,
there is confusion. The workaround is to prefix the function calls with the
schema.

Here is the SQL to expose the problem. Below I have included the commands
necessary to create the database, import the data, then dump and restore.
The restore is where we are seeing the bug.

—— SQL ——

create or replace function is_blank(data text)
returns boolean
language plpgsql
as $$
begin
return false;
end $$;

create or replace function has_content(data text)
returns boolean
language plpgsql
as $$
begin
return not is_blank(data);
end $$;

create schema g;

create table g.people (
id serial,
name varchar(50) not null,
check (has_content(name))
);

insert into g.people (name) values ('John’);

—— END SQL ——

—— TERMINAL OUTPUT ——

$ createdb -O postgres -U postgres dummy && psql -U postgres dummy <
dummy.sql
CREATE FUNCTION
CREATE FUNCTION
CREATE SCHEMA
CREATE TABLE
INSERT 0 1

$ createdb -U postgres dummy_restore && pg_dump -U postgres -Fc -Z9 dummy |
pg_restore -U postgres -d dummy_restore
pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 2367; 0 1055467702 TABLE
DATA people postgres
pg_restore: [archiver (db)] COPY failed for table "people": ERROR: function
is_blank(text) does not exist
LINE 1: SELECT not is_blank(data)
^
HINT: No function matches the given name and argument types. You might need
to add explicit type casts.
QUERY: SELECT not is_blank(data)
CONTEXT: PL/pgSQL function public.has_content(text) line 3 at RETURN
COPY people, line 1: "1 John"
WARNING: errors ignored on restore: 1

—— END TERMINAL OUTPUT ——

Thank you,

Jeremy Cowgar

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2017-05-12 18:13:54 Re: BUG #14649: Function Namespace Resolution Bug
Previous Message Bruce Momjian 2017-05-12 17:30:55 Re: BUG #14635: Query is executed slower on hot standby slave database then on master database