pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: John DeSoi <desoi@pgedit.com>
To: Daniel CAUNE <d.caune@free.fr>
Cc: pgsql-sql@postgresql.org
Subject: Re: Executing plpgsql scripts using psql, is that possible?
Date: Mon, 16 Jan 2006 08:50:58 -0500
Message-ID: <BC6BBB56-E7E8-402D-9B06-2034C0132458@pgedit.com> (raw)
In-Reply-To: <0IT6005QV7JN4WX1@VL-MO-MR004.ip.videotron.ca>
References: <0IT6005QV7JN4WX1@VL-MO-MR004.ip.videotron.ca>


On Jan 16, 2006, at 5:35 AM, Daniel CAUNE wrote:

> I would like to write some administration plpgsql scripts that  
> populate some tables (dimension tables) and to execute them using  
> psql.  I’m not sure that is possible with psql as it is with Oracle  
> sqlplus or SQL Server MSQuery:


If you want to execute a plpgsql function from a file using psql,  
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 := 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




view thread (6+ messages)  latest in thread

Message-ID: <BC6BBB56-E7E8-402D-9B06-2034C0132458@pgedit.com>
Permalink:  ../BC6BBB56-E7E8-402D-9B06-2034C0132458@pgedit.com/
Also on:    postgresql.org/message-id/BC6BBB56-E7E8-402D-9B06-2034C0132458@pgedit.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: desoi@pgedit.com, d.caune@free.fr
  Subject: Re: Executing plpgsql scripts using psql, is that possible?
  In-Reply-To: <BC6BBB56-E7E8-402D-9B06-2034C0132458@pgedit.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox