X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 20DF39DC83E for ; Mon, 16 Jan 2006 09:51:05 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 56661-04 for ; Mon, 16 Jan 2006 09:51:08 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from a2s5.a2hosting.com (host-209-124-50-10.a2webhosting.com [209.124.50.10]) by postgresql.org (Postfix) with ESMTP id 932D79DC810 for ; Mon, 16 Jan 2006 09:51:02 -0400 (AST) Received: from adsl-155-31-135.tys.bellsouth.net ([68.155.31.135] helo=[192.168.1.10]) by a2s5.a2hosting.com with esmtpsa (TLSv1:RC4-SHA:128) (Exim 4.52) id 1EyUlF-0007oh-Gr; Mon, 16 Jan 2006 08:51:05 -0500 In-Reply-To: <0IT6005QV7JN4WX1@VL-MO-MR004.ip.videotron.ca> References: <0IT6005QV7JN4WX1@VL-MO-MR004.ip.videotron.ca> Mime-Version: 1.0 (Apple Message framework v746.2) Content-Type: text/plain; charset=WINDOWS-1252; delsp=yes; format=flowed Message-Id: Cc: pgsql-sql@postgresql.org Content-Transfer-Encoding: quoted-printable From: John DeSoi Subject: Re: Executing plpgsql scripts using psql, is that possible? Date: Mon, 16 Jan 2006 08:50:58 -0500 To: Daniel CAUNE X-Mailer: Apple Mail (2.746.2) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - a2s5.a2hosting.com X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - pgedit.com X-Source: X-Source-Args: X-Source-Dir: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.141 required=5 tests=[AWL=0.141] X-Spam-Score: 0.141 X-Spam-Level: X-Archive-Number: 200601/88 X-Sequence-Number: 23877 On Jan 16, 2006, at 5:35 AM, Daniel CAUNE wrote: > I would like to write some administration plpgsql scripts that =20 > populate some tables (dimension tables) and to execute them using =20 > psql. I=92m not sure that is possible with psql as it is with Oracle =20= > sqlplus or SQL Server MSQuery: If you want to execute a plpgsql function from a file using psql, =20 just call it with SELECT. So your file might have: create or replace function my_function(params integer) returns integer as $$ DECLARE V_MyObjectID bigint; BEGIN V_MyObjectID :=3D RegisterMyObject('a string', 'another string'); AddObjectProperty(V_MyObjectID, 'a string'); AddObjectProperty(V_MyObjectID, 'another string'); .... END; $$ language plpgsql; SELECT my_function(1); and then psql -f script.sql my_db John DeSoi, Ph.D. http://pgedit.com/ Power Tools for PostgreSQL