pg.ddx.io pgsql-php@postgresql.org mailing list archive
help / color / mirror / Atom feedtransaction in postgres
2+ messages / 2 participants
[nested] [flat]
* transaction in postgres
@ 2002-09-19 16:37 Sebastiano Cascione <cascione.sr@tin.it>
0 siblings, 1 reply; 2+ messages in thread
From: Sebastiano Cascione @ 2002-09-19 16:37 UTC (permalink / raw)
To: pgsql-php
Hi averyone,
I'm using a new function to include two query into an unique transaction. Is
this the only way to do it? The following lines show you my function, the
purpose is to return the id_utente field (serial) of the last insert done:
----------------------------------------
CREATE FUNCTION "id_from_insert"("varchar", "varchar", "int4", "bpchar",
"varchar", "int4", "int4", "int4", "varchar", "int4", "bpchar", "varchar",
"varchar") RETURNS "int4" AS 'INSERT INTO g_registrazione_generale (
nome,
cognome,
data_di_nascita,
genere,
indirizzo,
codice_postale,
telefono,
id_documentazione,
email,
data_inserimento,
stato,
velocita_connessione,
istruzione
) VALUES (
$1,
$2,
$3,
$4,
$5,
$6,
$7,
$8,
$9,
$10,
$11,
$12,
$13
);
SELECT max(g_registrazione_generale.id_utente) FROM
g_registrazione_generale;
' LANGUAGE 'sql';
----------------------------------------------------------------------
Best regards
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: transaction in postgres
@ 2002-09-19 20:23 Miguel Carvalho <miguel@ipatimup.pt>
parent: Sebastiano Cascione <cascione.sr@tin.it>
0 siblings, 0 replies; 2+ messages in thread
From: Miguel Carvalho @ 2002-09-19 20:23 UTC (permalink / raw)
To: cascione.sr@tin.it; +Cc: pgsql-php
> Hi averyone,
> I'm using a new function to include two query into an unique
> transaction. Is this the only way to do it? The following lines show
> you my function, the purpose is to return the id_utente field (serial)
> of the last insert done: ----------------------------------------
> CREATE FUNCTION "id_from_insert"("varchar", "varchar", "int4",
> "bpchar", "varchar", "int4", "int4", "int4", "varchar", "int4",
> "bpchar", "varchar", "varchar") RETURNS "int4" AS 'INSERT INTO
> g_registrazione_generale ( nome,
> cognome,
> data_di_nascita,
> genere,
> indirizzo,
> codice_postale,
> telefono,
> id_documentazione,
> email,
> data_inserimento,
> stato,
> velocita_connessione,
> istruzione
> ) VALUES (
> $1,
> $2,
> $3,
> $4,
> $5,
> $6,
> $7,
> $8,
> $9,
> $10,
> $11,
> $12,
> $13
> );
> SELECT max(g_registrazione_generale.id_utente) FROM
> g_registrazione_generale;
> ' LANGUAGE 'sql';
Use a query like this: select curval('sequence_name') as nextid;
Before you can issue this query, you *must* have started a transaction(
begin work ).Its mutch simpler and you dont have to mess with record locking( in your
solution there is no garantee that you would get the max value, because
another connection may have inserted a new record ).
Miguel
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2002-09-19 20:23 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-09-19 16:37 transaction in postgres Sebastiano Cascione <cascione.sr@tin.it>
2002-09-19 20:23 ` Miguel Carvalho <miguel@ipatimup.pt>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox