Re: help with a procedure

From: Seref Arikan <serefarikan(at)gmail(dot)com>
To: Carlos Carcamo <eazyduiz(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: help with a procedure
Date: 2014-06-05 15:45:41
Message-ID: CA+4Thdo0b4LFv1Vi=qJ3MGeoq4+7LeUWSfYBfV7GQWxhmb4cDw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi Carlos,
Unless I'm missing something here, your queries are probably being called
from a programming language (java/c# etc) and your database access api
should support transactions. If you perform both operations under the same
db transaction and commit your transaction things should be fine. If there
is a problem with the first INSERT, your api should throw an exception and
you won't be able to commit the transaction (you may/may not need to call
rollback in your catch block), so it'll either be both calls executed or
none.

You may want to read about how db transactions are handled in your
programming environment.

Regards
Seref

On Thu, Jun 5, 2014 at 4:36 PM, Carlos Carcamo <eazyduiz(at)gmail(dot)com> wrote:

>
> 2014-06-05 9:32 GMT-06:00 Carlos Carcamo <eazyduiz(at)gmail(dot)com>:
>
> Hi everyone, I wonder if you could help me with a procedure that I would
>> like to perform in postgresql.
>>
>> I have an insert query like this:
>>
>> INSERT INTO products (product_id, description, price, qty, ...) values
>> ('01', 'some description', 10.15, 5, ...)
>>
>> then if there is no problem, perform another query like:
>>
>> INSERT INTO store(store_id, description, price, qty, ...) values ('02',
>> 'some description', 10.15, 5, ...)
>>
>> So the second query depends of the first query, if the first one succeed
>> the second will perform the second insert
>>
>> I would like to do something like:
>>
>> SELECT myProcedure(product_id, p_description, price, qty, store_id,
>> store_description );
>>
>> waiting for a response from procedure, maybe true or false.
>>
>> Thanks in advance...
>>
>>
>>
>> --
>> "El desarrollo no es material es un estado de conciencia metal"
>>
>
> Sorry, the second query looks like:
> INSERT INTO store(store_id, description, product_id, price, qty, ...)
> values ('02', 'some description', '01', 10.15, 5, ...)
>
> --
> "El desarrollo no es material es un estado de conciencia metal"
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bhushan Pathak 2014-06-05 16:11:45 Re: PostgreSQL 9.2.4 + CentOS 6.5 64 bit - segfault error in initdb
Previous Message Sébastien Lorion 2014-06-05 15:41:16 Re: Merge a sharded master into a single read-only slave