Thread: Starting a daemon process on INSERT

Starting a daemon process on INSERT

From
"P.V. Subramanian"
Date:
Hi all

I am writing an application which needs a daemon process to do some activity
as soon as certain types of records are added.

I don't want the daemon to continuously poll the DB, so I am trying to
create a trigger which would send some kind of signal to this daemon (or
even start a normal executable which terminates after finishing its job).

However I don't seem to be able to accomplish anything trigger driver driven
that would launch another external app. elog notices, SQL queries etc. work
but I want none of these!

Help appreciated.

PVS

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp


using the Text::Query perl module with postgresql

From
harrold@sage.che.pitt.edu
Date:
hey.

i was wondering if there was anyone out there using the Text::Query module
for perl. it's supposed to take a string in the form of altavistas search
syntax and produce a where clause for a select statement. i'm looking for
some examples if anyone has them.

thanks
john


How to quote in plpgsql function for Execute dynamic queries

From
"Phillip J. Allen"
Date:
Hi all,

I am trying to write a simple plpgsql function that executes a dynamic
function and cannot get the quotes right even after reading the programmer
manual.  I just can't seem to get my head around it.  This is what I am trying
to do.

CREATE FUNCTION myfunc(float8) RETURNS float8 AS '
    DECLARE
        dpsql varchar;
        dprec RECORD;
        a float8;
        f float8;
    BEGIN
        dpsql := 'Select d.a_parm, d.f_parm, d.deltax, d.deltay FROM c_g_datum
WHERE d.datum_id = ' || $1 || ';';      --this sql will only return 1 record

        FOR dprec IN EXCECUTE dpsql LOOP
            a := dprec.a_parm;
            f := dprec.f_parm;
        END LOOP;
--    DO SOME CALCUATIONS AND RETURN A FLOAT8 VALUE;
    END;'
LANGUAGE 'plpgsql';

So the real question is how do I formate the dpsql string.  I have returned
the string and executed an identical string in a querry and it works but for
some reason it bails out in an error when executed dynamically.

Does anyone have any fuctions that demonstrate how to properly quote
concatenated strings?  Even after reading the manual I am confused.  Thanks

Phillip J. Allen
Consulting Geochemist/Geologist
Lima Peru
e-mail: paallen@attglobal.net



Re: How to quote in plpgsql function for Execute dynamic queries

From
Tom Lane
Date:
"Phillip J. Allen" <paallen@attglobal.net> writes:
>         dpsql := 'Select d.a_parm, d.f_parm, d.deltax, d.deltay FROM c_g_datum
> WHERE d.datum_id = ' || $1 || ';';      --this sql will only return 1 record

> So the real question is how do I formate the dpsql string.

You need to double or backslash-escape all those ' marks.  Remember that
what you are writing is itself one big string literal --- that's how
CREATE FUNCTION sees it, anyway.  The form depicted above is what you
want the value of the string literal to be, after the string-literal
parser gets done with it.  So, use '' or \' anywhere you need plpgsql
to see a '.

Somewhere there is a handy page that illustrates how many quote marks
to write in various complicated situations.  I thought it was at
http://techdocs.postgresql.org/ but didn't have much luck finding it.
Anyone remember what I'm thinking of?

            regards, tom lane