Re: Executing plpgsql scripts using psql, is that possible?

Поиск
Список
Период
Сортировка
От Daniel CAUNE
Тема Re: Executing plpgsql scripts using psql, is that possible?
Дата
Msg-id 0IT700IG8S07GF90@VL-MO-MR002.ip.videotron.ca
обсуждение исходный текст
Ответ на Re: Executing plpgsql scripts using psql, is that possible?  (John DeSoi <desoi@pgedit.com>)
Ответы Re: Executing plpgsql scripts using psql, is that possible?  (Adrian Klaver <aklaver@comcast.net>)
Re: Executing plpgsql scripts using psql, is that possible?  (John DeSoi <desoi@pgedit.com>)
Список pgsql-sql

> -----Message d'origine-----
> De : pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-
> owner@postgresql.org] De la part de John DeSoi
> Envoyé : lundi 16 janvier 2006 08:51
> À : Daniel CAUNE
> Cc : pgsql-sql@postgresql.org
> Objet : Re: [SQL] Executing plpgsql scripts using psql, is that possible?
>
>
> 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
>

Yes, but that requires creating a function while I would prefer not having do so, as I said in my previous mail: "I
mean,without creating a function that wraps the whole, of course! :-)".  Why?  Actually this is not a function; this is
ascript that inserts static data into dimension tables such as Country, Language, etc. 

I have several scripts responsible for creating the database and all the objects (tables, views, constraints, indexes,
user-definedfunctions, etc.) of my project.  I would like to have some other scripts to initialize dimension tables,
i.e.inserting static data in those tables.  The idea is to automate the whole creation and initialization of a database
ona PostgreSQL server; I already have an Ant task that searches for SQL files, orders them, and runs them against the
specifieddatabase server.  The database and all relative objects are set up in one step. 

So, I completely understand that I can write an SQL script that:
 1 - creates a function that wraps SQL code that inserts static data into dimension tables. 2 - executes that function
3- destroys that function 

But actually that is a bit weird, isn't it?

Thanks,


Daniel



В списке pgsql-sql по дате отправления:

Предыдущее
От: Ottó Havasvölgyi
Дата:
Сообщение: Re: For update
Следующее
От: Adrian Klaver
Дата:
Сообщение: Re: Executing plpgsql scripts using psql, is that possible?