Search Postgresql Archives

Re: Switching from MySQL: ON DUPLICATE KEY UPDATE, plpgsql function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> >
> > Wouldn't you just be looking for something like:
> >
> > BEGIN;
> >  EXECUTE 'insert into forums_readposts values ('...')';
> >        EXCEPTION when unique_violation THEN
> >                EXECUTE 'update forums_readposts set lastpostread =
> '...' ';
> > END;

> > The logic as i read your post is. If the user's never done a
> "catchup" operation
> > before, this will create the record. If he has, then it will update
> this record
> > to reflect the new transid.
> >
> > Dave
> >
> 
> Hmm, yeah. I'm new to PostgreSQL, and have little experience with
> MySQL other than basic queries and joins. I didn't get to the part in
> the docs that covers EXECUTE yet, haha. That looks like it would do
> exactly what I want it to.
[Spotts, Christopher] 
There's a good example and some documentation of what Dave said in the manual at the bottom of this page.
http://www.postgresql.org/docs/current/static/plpgsql-control-structures.html
You should really only need to "EXECUTE" here if you have some dynamically determined columns or tables.  The "magic" here is a combination of "IF found" and "EXCEPTION WHEN unique violation"




-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux