create a dynamic function

From: salah jubeh <s_jubeh(at)yahoo(dot)com>
To: pgsql <pgsql-general(at)postgresql(dot)org>
Subject: create a dynamic function
Date: 2011-09-29 16:04:05
Message-ID: 1317312245.96273.YahooMailNeo@web161518.mail.bf1.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello Guys,

I have the following problem and I solved it in the following way, I need to see if there are a better approaches to do that. any suggestion is welcome

The problem

I have function have this logic 

FOR record1 in SELECT .... LOOP

     FRO record2 in SELECT ... LOOP
    

         -- Here the  function business logic changes based on a lookup table;  for example, the  there are many logical conditions AND and OR  and the decision of how to combine these logical conditions may change based on the lookup table

        -- i.e in some cases the logical condition might be  ' if record1. attribute1 = record2. attribute1 OR ....' or it may be  ' if record1. attribute1 = record2. attribute1 AND....'
         -- The number of attributes is very large (around 45) which means I have endless combination of these logical conditions  and also the lookup tables can be changed  
           

    END LOOP
END LOOP

So my solution was

to create atrriger on the  lookup table to create this function

DECLARE
    function_body TEXT := 'CREATE OR REPLACE .... '
    ..
BEGIN
    ...
    FOR RECORD  in the lookup table .....
        function_body = function_body

EXECUTE function_body
   ..

Regards

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2011-09-29 16:09:29 Re: bytea columns and large values
Previous Message Jon Nelson 2011-09-29 15:54:52 Re: bytea columns and large values