Re: MySql 'REPLACE'
От | Thomas Swan |
---|---|
Тема | Re: MySql 'REPLACE' |
Дата | |
Msg-id | 5.1.0.14.0.20010425082557.00ae1830@tangent.ics.olemiss.edu обсуждение исходный текст |
Ответ на | MySql 'REPLACE' (Alessio Bragadini <alessio@albourne.com>) |
Список | pgsql-sql |
At 4/25/2001 07:38 AM, you wrote:<br /><blockquote cite="cite" class="cite" type="cite">I am working in porting the Slashsoftware from MySql to PostgreSQL. I<br /> stepped in MySql's REPLACE command (a SQL command) that to my knowledge<br/> is not supported by PostgreSQL and it's not standard SQL. According to<br /> MySql's manual:<br /><br /> "REPLACEworks exactly like INSERT, except that if an old record in the<br /> table has the same value as a new record ona unique index, the old<br /> record is<br /> deleted before the new record is inserted. See section 7.21 INSERT<br />syntax."<br /><br /> REPLACE INTO table (column, column...) VALUES (value, value...)<br /><br /> Has anyone had any experienceabout how to simulate it under PostgreSQL?<br /> I am using Perl and I can move most of the thing into application<br/> anyway.</blockquote><br /> You should be able to do this with two separate queries inside a transaction.<br/><br /> The only part I'm not clear on is whether to use an 'and' or an 'or' on the delete. Check and seeif all values have to match or if partial matches, i.e. only one of the columns, are acceptable. If it does partial matching,then use the 'or', otherwise use the 'and'.<br /><br /> Give this a try...<br /><dl><dd>begin; <dd>delete from tablewhere (column=value) and (column=value) and ...; <dd>insert into table (column, column...) values (value, value...);<dd>end;<br /><br /></dl>From what you've given me, I think this would emulate that behavior.<br /><br /> Hopeit helps...<br />
В списке pgsql-sql по дате отправления: