Thread: INSERT before UPDATE?
Hello, I would like to ask you for an advice. There are two tables in my PostgreSQL database - main table with datas and second with translations for all languages of these records. When I try to UPDATE a record in the language table and this record doesn't exists there I need to INSERT into the language table (from default language version) and execute UPDATE statement again. Could you tell me if is this possible and if so - how to do it? Thank you in advance. -- Jiri Nemec http://www.meneashop.cz/
am Thu, dem 16.08.2007, um 10:30:01 +0200 mailte Ji?í N?mec folgendes: > Hello, > > I would like to ask you for an advice. > > There are two tables in my PostgreSQL database - main table with datas and > second with translations for all languages of these records. > > When I try to UPDATE a record in the language table and this record > doesn't exists there I need to INSERT into the language table (from > default language version) and execute UPDATE statement again. > > Could you tell me if is this possible and if so - how to do it? Okay, i try to ask our doc-bot on IRC: 11:15 < akretschmer> ??upsert 11:15 < rtfm_please> For information about upsert 11:15 < rtfm_please> see http://www.postgresql.org/docs/current/static/plpgsql-control-structures.html#PLPGSQL-UPSERT-EXAMPLE Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net
am Thu, dem 16.08.2007, um 14:11:07 +0200 mailte Ji??í N??mec folgendes: > > see > > http://www.postgresql.org/docs/current/static/plpgsql-control-structures.html#PLPGSQL-UPSERT-EXAMPLE > > Yes I see, but I'll try to describe it in more detail: > > I could write plpgsql trigger function which will UPDATE a record (or > INSERT new record) when the record is not found. But as far as I know > a trigger is not executed when a updated record is not found, so this > solution doesn't work for me. I don't want to change my application - > I would like to set this behaviour directly in PostgreSQL database so > I couldn't use a method from your example (...which requires that all > SQL UPDATE statements need to be modified). Maybe you can achieve this with a RULE. I'm not sure, but i would try ist. Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net