Обсуждение: sql query - create replace function

Поиск
Список
Период
Сортировка

sql query - create replace function

От
"Iuri Sampaio"
Дата:
Hi all,
 
I created a script to install postgresql. One of the steps is to run a sql query.
 
the problem is that i need to run the query as postgres user, plus it needs to be at psql shell prompt command line, i.e:
 
# from your shell prompt enter:
$ psql <dbname>
 
# From the psql prompt enter the follow plpgsql code to create the bitfromint4 function:

$ create or replace function bitfromint4 (integer) returns bit varying as ' begin return $1::bit(32); end;' language 'plpgsql' immutable strict;

#Exit psql:

$ \q 
 
 
 
I expected something like
su - postgres -c "pgsql dbname && create or replace function bitfromint4 (integer) returns bit varying as ' begin return $1::bit(32); end;' language 'plpgsql' immutable str\
ict;"
 
but i see when the script runs "pgsql dbname" the bash script looses control of the process, and there's no way back, from pgql shell prompt when it gets in, to continue the script
 
iuri

Re: sql query - create replace function

От
Richard Huxton
Дата:
Iuri Sampaio wrote:
> Hi all,
> 
> I created a script to install postgresql. One of the steps is to run a sql
> query.
> 
> the problem is that i need to run the query as postgres user, plus it needs
> to be at psql shell prompt command line, i.e:

Why does it need to be at the psql prompt?

> I expected something like
> su - postgres -c "pgsql dbname && create or replace function bitfromint4
> (integer) returns bit varying as ' begin return $1::bit(32); end;' language
> 'plpgsql' immutable str\
> ict;"

What's wrong with this?

--   Richard Huxton  Archonet Ltd