X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 96F6F56490 for ; Tue, 15 Mar 2005 11:48:09 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 06363-03 for ; Tue, 15 Mar 2005 11:48:07 +0000 (GMT) Received: from pd6mo2no.prod.shaw.ca (idcmail-mo2no.cg.shawcable.net [64.59.134.9]) by svr1.postgresql.org (Postfix) with ESMTP id 4F67856442 for ; Tue, 15 Mar 2005 11:48:06 +0000 (GMT) Received: from pd7mr3no.prod.shaw.ca (pd7mr3no-qfe3.prod.shaw.ca [10.0.144.130]) by l-daemon (Sun ONE Messaging Server 6.0 HotFix 1.01 (built Mar 15 2004)) with ESMTP id <0IDE00CM6644PZA0@l-daemon> for pgsql-sql@postgresql.org; Tue, 15 Mar 2005 04:48:04 -0700 (MST) Received: from pn7ml3no.prod.shaw.ca ([10.0.149.112]) by pd7mr3no.prod.shaw.ca (Sun ONE Messaging Server 6.0 HotFix 1.01 (built Mar 15 2004)) with ESMTP id <0IDE00GOR644WX90@pd7mr3no.prod.shaw.ca> for pgsql-sql@postgresql.org; Tue, 15 Mar 2005 04:48:04 -0700 (MST) Received: from Dell4500 (S01060004236fc1f7.wp.shawcable.net [24.77.13.13]) by l-daemon (iPlanet Messaging Server 5.2 HotFix 1.18 (built Jul 28 2003)) with SMTP id <0IDE00G08640PR@l-daemon> for pgsql-sql@postgresql.org; Tue, 15 Mar 2005 04:48:04 -0700 (MST) Date: Tue, 15 Mar 2005 05:48:03 -0600 From: George Weaver Subject: Re: Generic Function To: lucas@presserv.org, pgsql-sql@postgresql.org Message-id: <004b01c52954$dacb5ec0$6400a8c0@Dell4500> MIME-version: 1.0 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.2527 X-Mailer: Microsoft Outlook Express 6.00.2900.2527 Content-type: text/plain; reply-type=original; charset=iso-8859-1; format=flowed Content-transfer-encoding: 7bit X-Priority: 3 X-MSMail-priority: Normal References: <20050314151555.6kp8nfclzy5cogg0@www.presserv.org> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.49 tagged_above=0 required=5 tests=AWL, DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST, FORGED_RCVD_HELO X-Spam-Level: * X-Archive-Number: 200503/219 X-Sequence-Number: 20698 ----- Original Message ----- From: To: Sent: Monday, March 14, 2005 12:15 PM Subject: [SQL] Generic Function > Hi, > Can I built a generic function like: > CREATE FUNCTION f (text) RETURNS TEXT as > $$ > return 'select * from $1'; > $$ > I know its impossible as writed. Also I have looked for EXECUTE procedure > but it > not run the correct function. If you show us what you've tried and the results you received we may be able to help more. Some points: 1. To create a string to run with EXECUTE you would need to concatenate the above phrase: (Assuming "query" has been declared as text): query := 'Select * from ' || $1; 2. Since you're likely returning multiple rows, you need to write your function as a set-returning function. See: http://www.postgresql.org/docs/8.0/static/plpgsql-control-structures.html#PLPGSQL-RECORDS-ITERATING and Executing Dynamic Commands in http://www.postgresql.org/docs/8.0/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-PERFORM > Is there a way to construct this clause? Using plpgsql/pltcl/anything.... > ??? > > Thanks > > ---------------------------(end of broadcast)--------------------------- > TIP 5: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faq >