pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedDDL in transactions?
6+ messages / 3 participants
[nested] [flat]
* DDL in transactions?
@ 2005-03-31 07:32 Giuseppe Sacco <giuseppe@eppesuigoccas.homedns.org>
0 siblings, 1 reply; 6+ messages in thread
From: Giuseppe Sacco @ 2005-03-31 07:32 UTC (permalink / raw)
To: pgsql-jdbc
Hi,
I have a question about 7.4 jdbc driver. I am executing this code:
--------------------
conn=datasource.getPooledConnection().getConnection();
conn.setAutoCommit(false);
stmt=conn.createStatement();
stmt.executeUpdate("CREATE TABLE X (X VARCHAR(100))");
//stmt.commit(); // <= Look at this line
stmt.executeUpdate("INSERT INTO X VALUES ('string')");
stmt.commit();
stmt.close();
conn.close();
--------------------
And I found that, using postgresql jdbc driver, I need to add the
commit() call that is commented out, otherwise I get an error like
'relation X does not exists'.
My question is: why? Shouldn't DDL be executed immediately?
Thank you for your response,
Giuseppe Sacco
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: DDL in transactions?
@ 2005-03-31 16:09 Kris Jurka <books@ejurka.com>
parent: Giuseppe Sacco <giuseppe@eppesuigoccas.homedns.org>
0 siblings, 3 replies; 6+ messages in thread
From: Kris Jurka @ 2005-03-31 16:09 UTC (permalink / raw)
To: Giuseppe Sacco <giuseppe@eppesuigoccas.homedns.org>; +Cc: pgsql-jdbc
On Thu, 31 Mar 2005, Giuseppe Sacco wrote:
> Hi,
> I have a question about 7.4 jdbc driver. I am executing this code:
>
> --------------------
> conn=datasource.getPooledConnection().getConnection();
> conn.setAutoCommit(false);
> stmt=conn.createStatement();
>
> stmt.executeUpdate("CREATE TABLE X (X VARCHAR(100))");
> //stmt.commit(); // <= Look at this line
> stmt.executeUpdate("INSERT INTO X VALUES ('string')");
> stmt.commit();
>
> stmt.close();
> conn.close();
> --------------------
>
> And I found that, using postgresql jdbc driver, I need to add the
> commit() call that is commented out, otherwise I get an error like
> 'relation X does not exists'.
>
> My question is: why? Shouldn't DDL be executed immediately?
No. DDL in postgresql is fully transactable and may be rolled back or
committed. That doesn't explain why the above code doesn't work.
Because the two executeUpdates are on the same Statement on the same
Connection the second execution should see the newly created table because
it is in the same transaction. Perhaps you are not showing us the real
code you are using and you actually have two connections?
Kris Jurka
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: DDL in transactions?
@ 2005-03-31 17:24 Giuseppe Sacco <giuseppe@eppesuigoccas.homedns.org>
parent: Kris Jurka <books@ejurka.com>
2 siblings, 0 replies; 6+ messages in thread
From: Giuseppe Sacco @ 2005-03-31 17:24 UTC (permalink / raw)
To: pgsql-jdbc
Kris Jurka wrote:
[...]
>>My question is: why? Shouldn't DDL be executed immediately?
>
>
> No. DDL in postgresql is fully transactable and may be rolled back or
> committed. That doesn't explain why the above code doesn't work.
> Because the two executeUpdates are on the same Statement on the same
> Connection the second execution should see the newly created table because
> it is in the same transaction. Perhaps you are not showing us the real
> code you are using and you actually have two connections?
Thanks Kris, I am going to check it.
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: DDL in transactions?
@ 2005-03-31 17:34 Markus Schaber <schabi@logix-tt.com>
parent: Kris Jurka <books@ejurka.com>
2 siblings, 0 replies; 6+ messages in thread
From: Markus Schaber @ 2005-03-31 17:34 UTC (permalink / raw)
To: Kris Jurka <books@ejurka.com>; +Cc: Giuseppe Sacco <giuseppe@eppesuigoccas.homedns.org>; pgsql-jdbc
Hi, Giuseppe,
Kris Jurka schrieb:
>>My question is: why? Shouldn't DDL be executed immediately?
>
> No. DDL in postgresql is fully transactable and may be rolled back or
> committed. That doesn't explain why the above code doesn't work.
> Because the two executeUpdates are on the same Statement on the same
> Connection the second execution should see the newly created table because
> it is in the same transaction. Perhaps you are not showing us the real
> code you are using and you actually have two connections?
You can simply try this out via psql:
lwgeom=# begin;
BEGIN
lwgeom=# create table tester (a int);
CREATE TABLE
lwgeom=# insert into tester values (1);
INSERT 281855490 1
lwgeom=# rollback;
ROLLBACK
lwgeom=# select * from tester;
ERROR: relation "tester" does not exist
lwgeom=#
HTH,
Markus
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: DDL in transactions?
@ 2005-04-01 07:13 Giuseppe Sacco <giuseppe@eppesuigoccas.homedns.org>
parent: Kris Jurka <books@ejurka.com>
2 siblings, 1 reply; 6+ messages in thread
From: Giuseppe Sacco @ 2005-04-01 07:13 UTC (permalink / raw)
To: pgsql-jdbc
Il giorno gio, 31-03-2005 alle 11:09 -0500, Kris Jurka ha scritto:
[...]
> > My question is: why? Shouldn't DDL be executed immediately?
>
> No. DDL in postgresql is fully transactable and may be rolled back or
> committed. That doesn't explain why the above code doesn't work.
> Because the two executeUpdates are on the same Statement on the same
> Connection the second execution should see the newly created table because
> it is in the same transaction. Perhaps you are not showing us the real
> code you are using and you actually have two connections?
Hi Kris,
you was right: I used two different connections.
BTW, is it possible to disable this behaviour and have DDL statement
immediately executed?
Thanks,
Giuseppe
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: DDL in transactions?
@ 2005-04-01 07:32 Kris Jurka <books@ejurka.com>
parent: Giuseppe Sacco <giuseppe@eppesuigoccas.homedns.org>
0 siblings, 0 replies; 6+ messages in thread
From: Kris Jurka @ 2005-04-01 07:32 UTC (permalink / raw)
To: Giuseppe Sacco <giuseppe@eppesuigoccas.homedns.org>; +Cc: pgsql-jdbc
On Fri, 1 Apr 2005, Giuseppe Sacco wrote:
> BTW, is it possible to disable this behaviour and have DDL statement
> immediately executed?
>
No. If you want it to commit you must issue a commit.
Kris Jurka
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2005-04-01 07:32 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-03-31 07:32 DDL in transactions? Giuseppe Sacco <giuseppe@eppesuigoccas.homedns.org>
2005-03-31 16:09 ` Kris Jurka <books@ejurka.com>
2005-03-31 17:24 ` Giuseppe Sacco <giuseppe@eppesuigoccas.homedns.org>
2005-03-31 17:34 ` Markus Schaber <schabi@logix-tt.com>
2005-04-01 07:13 ` Giuseppe Sacco <giuseppe@eppesuigoccas.homedns.org>
2005-04-01 07:32 ` Kris Jurka <books@ejurka.com>
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