pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #10500: Cannot restore from a dump when some function is used in public shcema
5+ messages / 4 participants
[nested] [flat]

* BUG #10500: Cannot restore from a dump when some function is used in public shcema
@ 2014-06-02 16:14 nicolas@cybercat.ca
  2014-06-02 17:17 ` Re: BUG #10500: Cannot restore from a dump when some function is used in public shcema Andres Freund <andres@2ndquadrant.com>
  2014-06-02 18:11 ` Re: BUG #10500: Cannot restore from a dump when some function is used in public shcema Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 2 replies; 5+ messages in thread

From: nicolas@cybercat.ca @ 2014-06-02 16:14 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      10500
Logged by:          Nicolas Ross
Email address:      nicolas@cybercat.ca
PostgreSQL version: 9.3.4
Operating system:   CentOS 6.5
Description:        

Hi !

I have encountered a problem when restoring a database from a dump made with
pg_dump.

I narrow it down to this simple exemple. Here's a pg_dump in plain text of
my test case :

CREATE SCHEMA intranet;
CREATE EXTENSION IF NOT EXISTS unaccent WITH SCHEMA public;
SET search_path = public, pg_catalog;
CREATE FUNCTION cyunaccent(character varying) RETURNS character varying
    LANGUAGE sql IMMUTABLE
    AS $_$ SELECT unaccent(lower($1)); $_$;
-- At this stage, the cyunaccent function is created in the public shcema to
later be used by tables in all schema.
SET search_path = intranet, pg_catalog;
CREATE TABLE intranet.client (
    codeclient character varying(10) NOT NULL,
    noclient character varying(7),
    nomclient character varying(200) COLLATE pg_catalog."fr_CA"
);
ALTER TABLE ONLY client
    ADD CONSTRAINT client_pkey PRIMARY KEY (codeclient);

CREATE INDEX idx_clientnomclient ON client USING btree
(public.cyunaccent((lower((nomclient)::text))::character varying));

The pg_restore or psql won't create the index in the last sql, despite the
fact that the public schema is specified to reference the function.

The problem lies in the 

SET search_path = intranet, pg_catalog;

call.

Changing it to 

SET search_path = intranet, public, pg_catalog;

solves the problem.

I don't know if this is a bug in the way that the dump is produced or in the
way that the create index is done, but I beleive there is a bug here.


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: BUG #10500: Cannot restore from a dump when some function is used in public shcema
  2014-06-02 16:14 BUG #10500: Cannot restore from a dump when some function is used in public shcema nicolas@cybercat.ca
@ 2014-06-02 17:17 ` Andres Freund <andres@2ndquadrant.com>
  2014-06-02 17:22   ` Re: BUG #10500: Cannot restore from a dump when some function is used in public shcema Nicolas Ross <nicolas@cybercat.ca>
  1 sibling, 1 reply; 5+ messages in thread

From: Andres Freund @ 2014-06-02 17:17 UTC (permalink / raw)
  To: nicolas@cybercat.ca; +Cc: pgsql-bugs

Hi,

On 2014-06-02 16:14:27 +0000, nicolas@cybercat.ca wrote:
> The pg_restore or psql won't create the index in the last sql, despite the
> fact that the public schema is specified to reference the function.

What exactly do you mean with "won't create"? Does it generate an error?
If so, what's that exactly?

Greetings,

Andres Freund

-- 
 Andres Freund	                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: BUG #10500: Cannot restore from a dump when some function is used in public shcema
  2014-06-02 16:14 BUG #10500: Cannot restore from a dump when some function is used in public shcema nicolas@cybercat.ca
  2014-06-02 17:17 ` Re: BUG #10500: Cannot restore from a dump when some function is used in public shcema Andres Freund <andres@2ndquadrant.com>
@ 2014-06-02 17:22   ` Nicolas Ross <nicolas@cybercat.ca>
  0 siblings, 0 replies; 5+ messages in thread

From: Nicolas Ross @ 2014-06-02 17:22 UTC (permalink / raw)
  To: Andres Freund <andres@2ndquadrant.com>; +Cc: pgsql-bugs

Andres Freund a écrit :
> Hi,
>
> On 2014-06-02 16:14:27 +0000, nicolas@cybercat.ca wrote:
>> The pg_restore or psql won't create the index in the last sql, despite the
>> fact that the public schema is specified to reference the function.
> What exactly do you mean with "won't create"? Does it generate an error?
> If so, what's that exactly?

Yes, sorry, here it is :

ERROR:  function unaccent(text) does not exist
LIGNE 1 :  SELECT unaccent(lower($1));
                   ^
ASTUCE : No function matches the given name and argument types. You 
might need to add explicit type casts.
REQUÊTE :  SELECT unaccent(lower($1));
CONTEXTE : SQL function "cyunaccent" during inlining

********** Error **********

ERROR: function unaccent(text) does not exist
SQL state: 42883
Hint: No function matches the given name and argument types. You might 
need to add explicit type casts.
Context: SQL function "cyunaccent" during inlining




-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: BUG #10500: Cannot restore from a dump when some function is used in public shcema
  2014-06-02 16:14 BUG #10500: Cannot restore from a dump when some function is used in public shcema nicolas@cybercat.ca
@ 2014-06-02 18:11 ` Tom Lane <tgl@sss.pgh.pa.us>
  2014-06-02 19:39   ` Re: BUG #10500: Cannot restore from a dump when some function is used in public shcema Nicolas Ross <nicolas@cybercat.ca>
  1 sibling, 1 reply; 5+ messages in thread

From: Tom Lane @ 2014-06-02 18:11 UTC (permalink / raw)
  To: nicolas@cybercat.ca; +Cc: pgsql-bugs

nicolas@cybercat.ca writes:
> I narrow it down to this simple exemple. Here's a pg_dump in plain text of
> my test case :

> CREATE SCHEMA intranet;
> CREATE EXTENSION IF NOT EXISTS unaccent WITH SCHEMA public;
> SET search_path = public, pg_catalog;
> CREATE FUNCTION cyunaccent(character varying) RETURNS character varying
>     LANGUAGE sql IMMUTABLE
>     AS $_$ SELECT unaccent(lower($1)); $_$;

This function is unsafe on its face: it does not specify what schema to
find unaccent() in.  You need to either explicitly schema-qualify:

     SELECT public.unaccent(lower($1));

(for good measure it'd be wise to qualify lower() as well), or else attach
a "SET search_path" clause to the function definition.

It's arguable whether the search path sensitivity of such functions is
a feature or a bug.  But there are people depending on the fact that they
can change the search path and get different results, so it's unlikely
we'd change the definition now.

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: BUG #10500: Cannot restore from a dump when some function is used in public shcema
  2014-06-02 16:14 BUG #10500: Cannot restore from a dump when some function is used in public shcema nicolas@cybercat.ca
  2014-06-02 18:11 ` Re: BUG #10500: Cannot restore from a dump when some function is used in public shcema Tom Lane <tgl@sss.pgh.pa.us>
@ 2014-06-02 19:39   ` Nicolas Ross <nicolas@cybercat.ca>
  0 siblings, 0 replies; 5+ messages in thread

From: Nicolas Ross @ 2014-06-02 19:39 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs

Tom Lane a écrit :

>> I narrow it down to this simple exemple. Here's a pg_dump in plain text of
>> my test case :
>> CREATE SCHEMA intranet;
>> CREATE EXTENSION IF NOT EXISTS unaccent WITH SCHEMA public;
>> SET search_path = public, pg_catalog;
>> CREATE FUNCTION cyunaccent(character varying) RETURNS character varying
>>      LANGUAGE sql IMMUTABLE
>>      AS $_$ SELECT unaccent(lower($1)); $_$;
> This function is unsafe on its face: it does not specify what schema to
> find unaccent() in.  You need to either explicitly schema-qualify:
>
>       SELECT public.unaccent(lower($1));
>
> (for good measure it'd be wise to qualify lower() as well), or else attach
> a "SET search_path" clause to the function definition.
>
> It's arguable whether the search path sensitivity of such functions is
> a feature or a bug.  But there are people depending on the fact that they
> can change the search path and get different results, so it's unlikely
> we'd change the definition now.
>
> 			regards, tom lane
Oh !

Thanks for pointing that out. I modified my function definition and now 
my restore can complete without an error.

Regards,


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2014-06-02 19:39 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-06-02 16:14 BUG #10500: Cannot restore from a dump when some function is used in public shcema nicolas@cybercat.ca
2014-06-02 17:17 ` Andres Freund <andres@2ndquadrant.com>
2014-06-02 17:22   ` Nicolas Ross <nicolas@cybercat.ca>
2014-06-02 18:11 ` Tom Lane <tgl@sss.pgh.pa.us>
2014-06-02 19:39   ` Nicolas Ross <nicolas@cybercat.ca>

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