Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id C7D7DF172E1 for ; Wed, 4 Jul 2012 03:42:02 -0300 (ADT) Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SmJHj-0005bU-SI for pgsql-bugs@postgresql.org; Wed, 04 Jul 2012 06:42:01 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id q646fkNJ009782; Wed, 4 Jul 2012 02:41:46 -0400 (EDT) From: Tom Lane To: jgd@well.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #6715: 9.2b2 psql \ir does not understand leading ../ In-reply-to: References: Comments: In-reply-to jgd@well.com message dated "Wed, 04 Jul 2012 02:55:30 -0000" Date: Wed, 04 Jul 2012 02:41:46 -0400 Message-ID: <9781.1341384106@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201207/16 X-Sequence-Number: 33492 jgd@well.com writes: > When I do > \ir ../bar.sql > I get the bar.sql file in the CWD. AFAICS, it works fine when \ir is used interactively. However, you seem to be using it from a script: > $ psql -aX greg -f foo.sql and then indeed it does not work so well. psql is trying to evaluate the \ir relative to the script file's location, using this code: snprintf(relpath, MAXPGPATH, "%s", pset.inputfile); get_parent_directory(relpath); join_path_components(relpath, relpath, filename); canonicalize_path(relpath); The get_parent_directory() call reduces "foo.sql" to an empty string, which seems a tad bogus --- wouldn't "." be better? But in any case, join_path_components() thinks it can process a "../" prefix of the tail argument by stripping a directory name from the head argument, and there's nothing there to strip. So IMO join_path_components() is flat-out broken when applied to a non-absolute head path. Not sure about what a useful solution would be. regards, tom lane