X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 7CD859FB271 for ; Fri, 11 Aug 2006 10:03:35 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 74854-03 for ; Fri, 11 Aug 2006 10:03:27 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 277899FB263 for ; Fri, 11 Aug 2006 10:03:27 -0300 (ADT) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id C150D30AF3; Fri, 11 Aug 2006 15:03:25 +0200 (MET DST) From: Christopher Browne X-Newsgroups: pgsql.sql Subject: Re: sql error creating function Date: Fri, 11 Aug 2006 08:48:19 -0400 Organization: cbbrowne Computing Inc Lines: 44 Message-ID: <87veoztp4c.fsf@wolfe.cbbrowne.com> References: <44DBD05C.9020800@acm.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@news.hub.org X-message-flag: Outlook is rather hackable, isn't it? X-Home-Page: http://www.cbbrowne.com/info/ X-Affero: http://svcs.affero.net/rm.php?r=cbbrowne User-Agent: Gnus/5.1007 (Gnus v5.10.7) XEmacs/21.4.19 (linux) Cancel-Lock: sha1:8Cl8H9I/J8xBIfD+ycLlhz21soE= To: pgsql-sql@postgresql.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1 tagged_above=0 required=5 tests=AWL, INFO_TLD X-Spam-Level: * X-Archive-Number: 200608/80 X-Sequence-Number: 26038 Quoth tjo@acm.org ("TJ O'Donnell"): > When I psql -f f.sql > I get the following error: > psql:f.sql:10: ERROR: relation "fragset" does not exist > CONTEXT: SQL function "fragments" > >> cat f.sql > Create Or Replace Function fragments(character varying) > Returns setof character varying > As $$ > > Create Temporary Table fragset (smiles character varying); > Insert into fragset Values ('COCNC'); > Insert into fragset Values ('COCNCc1ccccc1'); > Select smiles from fragset; > > $$ Language SQL; > > But, if I paste into a running psql the commands: > > Create Temporary Table fragset (smiles character varying); > Insert into fragset Values ('COCNC'); > Insert into fragset Values ('COCNCc1ccccc1'); > Select smiles from fragset; > > it works fine. > > What is wrong in the function definition? > I'm using 8.1.3 Presumably it's that the query plan is evaluated based on the state of the database *before* the function runs, at which point table 'fragset' does not exist. Creation of the temp table will work fine, but the references to it don't, because when the query (to run the whole thing) is planned, the table doesn't exist. What you need to do is to generate the various queries on fragset as dynamic queries, invoked via "execute." That will cause the planner to run on each statement... -- output = reverse("moc.liamg" "@" "enworbbc") http://linuxdatabases.info/info/wp.html "We believe Windows 95 is a walking antitrust violation" -- Bryan Sparks