Обсуждение: Transactions within a function

Поиск
Список
Период
Сортировка

Transactions within a function

От
Daniel Åkerud
Дата:
Do the BEGIN and END in a function also indicate that it is done in a transaction?
Or can you put another BEGIN TRANSACTION; END TRANSACTION; in there?
 
---
Daniel Åkerud
 
[ Don't underestimate the power of stupid people in large groups]

Re: Transactions within a function

От
Jan Wieck
Дата:
Daniel Åkerud wrote:
> Do the BEGIN and END in a function also indicate that it is done in a transaction?
> Or can you put another BEGIN TRANSACTION; END TRANSACTION; in there?

    The  BEGIN  and  END  keywords in PL/pgSQL have absolutely no
    transactional meaning. They group statements into blocks with
    the  possibility  of  named blocks using the <<label>> syntax
    and then beeing able to EXIT  up  multiple  block  levels  at
    once.

    Since  every  SQL statement sent to the backend outside of an
    explicit transaction block has it's own implicit  transaction
    and   we   don't   have  subtransactions  yet,  there  is  no
    possibility for transaction control inside of functions.


Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me.                                  #
#================================================== JanWieck@Yahoo.com #



_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


Re: Transactions within a function

От
Doug McNaught
Дата:
Daniel �kerud <zilch@home.se> writes:

> Do the BEGIN and END in a function also indicate that it is done in a
> transaction?  Or can you put another BEGIN TRANSACTION; END
> TRANSACTION; in there?

Please don't post in HTML.

A function is always executed within a transaction--either an explicit
one (where the user issues BEGIN TRANSACTION) or the implicit
transaction created by issuing a single SQL statememt.  Since PG
doesn't allow nested transactions, you can't have a transaction inside
a function.

-Doug
--
The rain man gave me two cures; he said jump right in,
The first was Texas medicine--the second was just railroad gin,
And like a fool I mixed them, and it strangled up my mind,
Now people just get uglier, and I got no sense of time...          --Dylan

Cross database foreign keys

От
Morgan Curley
Дата:
Does anyone know if it is possible to connect to a differernt db from within a plsql function.
I have multilple inter-related schemas and want to enforce some fk relationships.

Thanks,
Morgan 

Re: Transactions within a function

От
Alex Pilosov
Дата:
On Fri, 6 Jul 2001, [iso-8859-1] Daniel �kerud wrote:

> Do the BEGIN and END in a function also indicate that it is done in a
> transaction? Or can you put another BEGIN TRANSACTION; END
> TRANSACTION; in there?

No. Functions cannot start/stop transactions, as postgresql does not
currently support nested transactions. BEGIN/END are pascalish/adaish
things identical to { and } in C.

-alex


Re: [SQL] Cross database foreign keys

От
Peter Eisentraut
Дата:
Morgan Curley writes:

> Does anyone know if it is possible to connect to a differernt db from
> within a plsql function.
> I have multilple inter-related schemas and want to enforce some fk
> relationships.

Not possible

--
Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter


Re: Transactions within a function

От
Peter Eisentraut
Дата:
Daniel Åkerud writes:

> Do the BEGIN and END in a function also indicate that it is done in a transaction?

No.

> Or can you put another BEGIN TRANSACTION; END TRANSACTION; in there?

No.

--
Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter


Re: Cross database foreign keys

От
Jan Wieck
Дата:
Morgan Curley wrote:
> Does anyone know if it is possible to connect to a differernt db from
> within a plsql function.
> I have multilple inter-related schemas and want to enforce some fk
> relationships.

    PL/pgSQL  doesn't support external database connects. PL/TclU
    does.

    But keep in mind that with this kind of setup you don't  have
    two  phase  commits,  and  that  updates  done through such a
    trigger (e.g. cascades)  will  not  rollback  if  your  local
    update does so after it got fired, because you have to commit
    the remote transaction before you know if your local one ever
    will.


Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me.                                  #
#================================================== JanWieck@Yahoo.com #



_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com