Re: Switching from MySQL: ON DUPLICATE KEY UPDATE, plpgsql function
| От | Chris Spotts |
|---|---|
| Тема | Re: Switching from MySQL: ON DUPLICATE KEY UPDATE, plpgsql function |
| Дата | |
| Msg-id | 002f01c9fa3f$9e54efe0$dafecfa0$@com обсуждение исходный текст |
| Ответ на | Re: Switching from MySQL: ON DUPLICATE KEY UPDATE, plpgsql function (APseudoUtopia <apseudoutopia@gmail.com>) |
| Список | pgsql-general |
> >
> > 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"
hereis a combination of "IF found" and "EXCEPTION WHEN unique violation"
В списке pgsql-general по дате отправления: