contempating installing a insert,update trigger on forums_topics table something like SET search_path = public; CREATE TRIGGER "MyTableName_Trig" AFTER INSERT OR DELETE OR UPDATE ON "forum_topics" FOR EACH ROW EXECUTE PROCEDURE "FORUM_CATCH_UP_ALL" (); HTH Martin ______________________________________________ Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen. Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni. Date: Sat, 27 Jun 2009 21:13:23 -0400 From: justin@xxxxxxxxxxxxxxx To: apseudoutopia@xxxxxxxxx; pgsql-general@xxxxxxxxxxxxxx Subject: Re: Switching from MySQL: ON DUPLICATE KEY UPDATE, plpgsql function APseudoUtopia wrote: Wouldn't a view be better than having a table that is deleted and updated all the time. I would add a field in the user table called last_login type timestamp then do a select from the forums table to generate this table where last_login <= FormTimeStamp .Hey list, I don't see the point having this table when a view would work better. Obviously this will not work with PostgreSQL. I've googled around a -- We could get a unique-key failure if you want to do something like this either do a test first to see if the key is present in the table, update or do an insert like this There is no reason to do a loop in the function waiting for a lock to clear. Postgresql Locks do not work like MySQL. CREATE FUNCTION FORUM_CATCH_UP_ALL (pUserID INTEGER) RETURNS VOID ASselect lastpostread from forums_readposts where userid = pUserId; if ( found() ) then UPDATE forums_readposts SET "lastpostread" = (SELECT lastpost FROM forums_topics WHERE blah blah) ; --its helpful to post the entire function ; else INSERT INTO forums_readposts ( userid, threadid, lastpostread) (SELECT $1, id, lastpost FROM forums_topics) WHERE userid = pUserID; end; END; I got the structure from the example in the postgresql documentation. Creating a view would work better and than creating a table to track this. I would think this website tracks the last time the user logged in correct??? This is going to create allot of over head maintaining this table when a simple select statement will work so much better if i understand what you are doing..... Lauren found her dream laptop. Find the PC that’s right for you. |