Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 7E0441337B82 for ; Thu, 3 Feb 2011 07:53:06 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 52901-05 for ; Thu, 3 Feb 2011 11:52:59 +0000 (UTC) X-Greylist: delayed 00:15:23.269355 by SQLgrey-1.7.6 Received: from smtpcorp.com (smtpcorp.com [174.143.60.32]) by mail.postgresql.org (Postfix) with ESMTP id CF94E1337B5C for ; Thu, 3 Feb 2011 07:52:58 -0400 (AST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpcorp.com; s=main; h=References:Message-ID:Date:Subject:From:To; bh=NKFALcu5yTHC2qUNofwxpclHTDfiZjbsWibEn/uUn/M=; b=FmXFCnL0l37iq12UTb+eyrREXuucXzb90U6OAEQ/IJsC1AY4W1SO8Sn8BCRybujqHZUF3KWWObDSJPFxTy/nzmxDajo9xW7BslbncCpW98k2gp8+grocmYhblRjagzo7; Received: from ip-118-90-139-176.xdsl.xnet.co.nz ([118.90.139.176] helo=gonzo) by smtpcorp.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.70) id 1PkxVI-00030n-S2; mid 144 for pgsql-bugs@postgresql.org; Thu, 03 Feb 2011 11:37:37 +0000 Received: from news by gonzo with local (Exim 4.72) (envelope-from ) id 1PkxV3-00030N-Pr for pgsql-bugs@postgresql.org; Fri, 04 Feb 2011 00:37:21 +1300 To: pgsql-bugs@postgresql.org Path: not-for-mail From: Jasen Betts Newsgroups: gmane.comp.db.postgresql.bugs Subject: Re: Feature request: include script file into function body Date: 3 Feb 2011 11:37:21 GMT Organization: Dis (not Dat) Organisation Lines: 42 Message-ID: References: <20110201112120.GA1327@cashmere.aip.de> NNTP-Posting-Host: localhost X-Trace: reversiblemaps.ath.cx 1296733041 11553 127.0.0.1 (3 Feb 2011 11:37:21 GMT) X-Face: ?)Aw4rXwN5u0~$nqKj`xPz>xHCwgi^q+^?Ri*+R(&uv2=E1Q0Zk(>h!~o2ID@6{uf8s; a +M[5[U[QT7xFN%^gR"=tuJw%TXXR'Fp~W; (T"1(739R%m0Yyyv*gkGoPA.$b,D.w:z+<'"=-lVT?6 {T?=R^:W5g|E2#EhjKCa+nt":4b}dU7GYB*HBxn&Td$@f%.kl^:7X8rQWd[NTc"P"u6nkisze/Q; 8 "9Z{peQF,w)7UjV$c|RO/mQW/NMgWfr5*$-Z%u46"/00mx-,\R'fLPe.)^ User-Agent: slrn/pre1.0.0-18 (Linux) X-Smtpcorp-Track: 21992046.1.61053490 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201102/48 X-Sequence-Number: 29320 On 2011-02-01, Steve White wrote: > Hi > > I asked on pgsql-general 31 Jan 2011 if there were a way to do this, and got > no response, so let's make it a feature request. > > It would be really nice to have a way to load script (especially Python > and Perl) from a separate file into a function body. Some advantages would > be: to run a code checker outside of Postgresql, and to make things easier > for source code colorizers. > > I have in mind syntax something like> >================================================ > CREATE OR REPLACE FUNCTION > myfunc( ... ) > RETURNS VOID FROM 'ScriptFile.py' LANGUAGE PLPYTHONU; >================================================ others have complained about the backend reading files maybe this coould be implemented in PSQL instead. (like \i and \copy are...) something like: \CREATE OR REPLACE FUNCTION myfunc( ... ) RETURNS VOID FROM 'ScriptFile.py' LANGUAGE PLPYTHONU psql would then need to slurp the file and quote the function body, but pq_escape_string_conn is presumably upto that task. on the other hand binary fuunctions (eg C) are read from files, but not directly by the backend, dlopen (or equivalent) is used instead. on the other hand, for symmetry I guess a form that matches yours is needed too, but, if using named files that will probably need database superuser permission (like the other named file functions do). Then ther could be an unpriviledged "from stdin" variant that psql could use to send the content (instead of quoting it and sending it in-line). ISTR C functions need superuser too.