Обсуждение: Can I call unix/linux commands within plsql?
Hello,
I'm new to Postgresql/plsql. Can anyone tell me that whether I can call unix/linux commands within plsql or not? I need it because some functions can not be provided by the PostgreSQL server itself such as email.
Thank you!!
Timmy
i'm not sure if is the right answer to your question anyway from psql prompt you can call a shell command by \! <cmd> andrea ps I apologise my terrible english.
There are two ways I can think of 1) Write a Perl, Pyton, C, or C++ program that calls PostgreSQL and also makes the system calls you need. 2) Write a function (see man create_function) in C. your C function can do anything. I'm guessing you should be doing #1. But tell us your application if you want better advice. --- Timmy �H�K�� <timmy.tang@gaojin.com> wrote: > Hello, > > I'm new to Postgresql/plsql. Can anyone tell me that whether I can > call unix/linux commands within plsql or not? I need it because some > functions can not be provided by the PostgreSQL server itself such as > email. > > Thank you!! > > Timmy > ===== Chris Albertson Home: 310-376-1029 chrisalbertson90278@yahoo.com Cell: 310-990-7550 Office: 310-336-5189 Christopher.J.Albertson@aero.org __________________________________________________ Do You Yahoo!? Check out Yahoo! Shopping and Yahoo! Auctions for all of your unique holiday gifts! Buy at http://shopping.yahoo.com or bid at http://auctions.yahoo.com
I think that there is a plshell implementation rolling around somewhere, but what I generally do is launch a cron script every so often that can then check up on PostgreSQL. For example, let's say you have a table emails_to_send. Cron can wake up a script that sends your emails for you, and the script is free to use PostgreSQL's excellent transaction support (something a shell script called from PostgreSQL cannot really do). Jason Timmy 鄧添喜 <timmy.tang@gaojin.com> writes: > Hello, > > > > I'm new to Postgresql/plsql. Can anyone tell me that whether I can call > unix/linux commands within plsql or not? I need it because some functions can > not be provided by the PostgreSQL server itself such as email. > > > > Thank you!! > > > > Timmy
On Thu, 13 Dec 2001, [big5] Timmy �H�K�� wrote: > Hello, > > I'm new to Postgresql/plsql. Can anyone tell me that whether I can > call unix/linux commands within plsql or not? I need it because some > functions can not be provided by the PostgreSQL server itself such as > email. Not directly. You can do this from C, but you need to be careful, because anything you do outside of the database is not transaction safe (ie, if something rolls back the transaction after the function is called, the outside things are still done even though any data changes are not recorded).
Missed the first post, and take what Stephen says as important regarding transactions ,etc... but here's a link to a unix shell language handler for postgres. http://www.ca.postgresql.org/~petere/plsh.html Never used it myself, but there it is. I've also seen (maybe in contrib? maybe somewhere else) a sendmail function (in C) that allows you to send email from within plsql. If you search the archives you'll find it. -philip On Thu, 13 Dec 2001, Stephan Szabo wrote: > > On Thu, 13 Dec 2001, [big5] Timmy �H�K�� wrote: > > > Hello, > > > > I'm new to Postgresql/plsql. Can anyone tell me that whether I can > > call unix/linux commands within plsql or not? I need it because some > > functions can not be provided by the PostgreSQL server itself such as > > email. > > Not directly. You can do this from C, but you need to be careful, > because anything you do outside of the database is not transaction > safe (ie, if something rolls back the transaction after the function > is called, the outside things are still done even though any data > changes are not recorded). > > > ---------------------------(end of broadcast)--------------------------- > TIP 6: Have you searched our list archives? > > http://archives.postgresql.org >
On Thu, 13 Dec 2001, Philip Hallstrom wrote: > Missed the first post, and take what Stephen says as important regarding > transactions ,etc... but here's a link to a unix shell language handler > for postgres. > > http://www.ca.postgresql.org/~petere/plsh.html > > Never used it myself, but there it is. > > I've also seen (maybe in contrib? maybe somewhere else) a sendmail > function (in C) that allows you to send email from within plsql. If you > search the archives you'll find it. That's pgMail. You'll find a link to it on the Interfacing page on the website. Vince. -- ========================================================================== Vince Vielhaber -- KA8CSH email: vev@michvhf.com http://www.pop4.net 56K Nationwide Dialup from $16.00/mo at Pop4 Networking Online Campground Directory http://www.camping-usa.com Online Giftshop Superstore http://www.cloudninegifts.com ==========================================================================