pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: asier.lostale@openbravo.com
Subject: BUG #15122: can't import data if table has a constraint with a function calling another function
Date: Tue, 20 Mar 2018 09:31:03 +0000
Message-ID: <152153826367.11956.8092048336300020216@wrigleys.postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      15122
Logged by:          Asier Lostalé
Email address:      asier.lostale@openbravo.com
PostgreSQL version: 9.3.22
Operating system:   ubuntu
Description:        

Using only public schema, data in tables that use in check constraints
functions that invoke other functions does not get imported with pg_restore
after it was dumped with pg_dump. But if functions in check constraints do
not invoke other functions, data is correctly imported.

I have noted this behavior after minor upgrading from 9.3.22 to 9.3.23 and
from 9.4.16 to 9.4.17; in 9.3.22 and 9.3.17 it worked fine.

I understand is due to changes in search_path
(https://bucardo.org/postgres_all_versions.html#version_9.3.22).

But it's unclear to me why having one level public functions is allowed but
it is not those functions to invoke other ones. It looks inconsistent.

For example, having this structure and data:

CREATE OR REPLACE FUNCTION is_even(n integer) RETURNS boolean AS $BODY$ 
BEGIN
  return n%2 = 0;  
END ; $BODY$  LANGUAGE plpgsql;

CREATE OR REPLACE FUNCTION is_even_positive(n integer) RETURNS boolean AS
$BODY$ 
BEGIN
  return is_even(n) and n > 0;  
END ; $BODY$  LANGUAGE plpgsql;


CREATE TABLE test_check (
  n integer
  CONSTRAINT even_chk CHECK (is_even(n)));

CREATE TABLE test_check2(
  n integer
  CONSTRAINT even_positive_chk CHECK (is_even_positive(n)));

insert into test_check values (2);
insert into test_check values (-2);
insert into test_check2 values (2);
Exporting it with:

pg_dump -h localhost -p 5432  -F c -b -v -f test.dmp test -U test
And importing it in a new database:

$ pg_restore -d test2 -U test -v test.dmp -h localhost
pg_restore: connecting to database for restore
pg_restore: creating SCHEMA "public"
pg_restore: creating COMMENT "SCHEMA public"
pg_restore: creating EXTENSION "plpgsql"
pg_restore: creating COMMENT "EXTENSION plpgsql"
pg_restore: creating FUNCTION "public.is_even(integer)"
pg_restore: creating FUNCTION "public.is_even_positive(integer)"
pg_restore: creating TABLE "public.test_check"
pg_restore: creating TABLE "public.test_check2"
pg_restore: processing data for table "public.test_check"
pg_restore: processing data for table "public.test_check2"
pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 2035; 0 7784774 TABLE DATA
test_check2 tad
pg_restore: [archiver (db)] COPY failed for table "test_check2": ERROR: 
function is_even(integer) does not exist
LINE 1: SELECT is_even(n) and n > 0
               ^
HINT:  No function matches the given name and argument types. You might need
to add explicit type casts.
QUERY:  SELECT is_even(n) and n > 0
CONTEXT:  PL/pgSQL function public.is_even_positive(integer) line 3 at
RETURN
COPY test_check2, line 1: "2"
pg_restore: creating ACL "SCHEMA public"
WARNING: errors ignored on restore: 1






view thread (5+ messages)  latest in thread

Message-ID: <152153826367.11956.8092048336300020216@wrigleys.postgresql.org>
Permalink:  ../152153826367.11956.8092048336300020216@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/152153826367.11956.8092048336300020216@wrigleys.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, asier.lostale@openbravo.com
  Subject: Re: BUG #15122: can't import data if table has a constraint with a function calling another function
  In-Reply-To: <152153826367.11956.8092048336300020216@wrigleys.postgresql.org>
  References: <152153826367.11956.8092048336300020216@wrigleys.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox