conditional execution of insert/update-s
conditional execution of insert/update-s
От:
Dmitry Teslenko <dteslenko@gmail.com>
Дата:
Hello! Question is what's the easiest way to implement conditional execution of insert/update-s via psql interface? As far as I know there's following options: 1) create function in procedural language (plpgsql, for example); then call that function 2) update ... where ; insert ... (select ... where ); not sure here if can be unrelated to the table being modified by update/insert statement; Are there alternatives? -- A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing in e-mail?
Re: conditional execution of insert/update-s
От:
Jasen Betts <jasen@xnet.co.nz>
Дата:
On 2009-01-22, Dmitry Teslenko wrote:
> Hello!
> Question is what's the easiest way to implement conditional execution
> of insert/update-s via psql interface?
>
> As far as I know there's following options:
> 1) create function in procedural language (plpgsql, for example);
> then call that function
> 2) update ... where ;
insert ... (select ... where );
> not sure here if can be unrelated to the table being modified
> by update/insert statement;
they can be unrelated
> Are there alternatives?
here's one but it's messy when the condition is false.
BEGIN;
SELECT expression_which_causes_an_exception_when_condition_fails;
statements...;
COMMIT;
the advantage of this is that it can be used with DDL statements.