Re: Transaction issue

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Rich Shepard <rshepard(at)appl-ecosys(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Transaction issue
Date: 2024-06-19 21:03:33
Message-ID: 039e657e-5dbc-4243-8c82-865ccb2c2fe5@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 6/19/24 13:54, Rich Shepard wrote:
> On Wed, 19 Jun 2024, Adrian Klaver wrote:
>
>> Looks to me you have a left over unresolved transaction in your psql
>> session. The easiest solution if that is the case is to exit the
>> session and start a new session to run the script.
>
> Adrian, et al.:
>
> That's what I've done. This time I commented out the BEGIN; line:
> bustrac=# \i insert-law-offices-addr.sql INSERT 0 66
>
> There are no errors in the file but when I tried running it as a
> transaction
> it failed.
>
> I have not before used transactions when inserting or updating tables; I'm
> surprised that starting the transaction from the psql command line chokes
> the attempt.

It shouldn't:

cat transaction_test.sql
BEGIN;
insert into transaction_test values(1, 'test'), (2, 'dog'), (3, 'cat');

test=# create table transaction_test(id integer, fld_1 varchar);

test=# \i transaction_test.sql
BEGIN
INSERT 0 3

test=*# commit ;
COMMIT

test=# select * from transaction_test ;
id | fld_1
----+-------
1 | test
2 | dog
3 | cat
(3 rows)

>
> Regards,
>
> Rich
>
>
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2024-06-19 21:09:56 Re: Transaction issue
Previous Message Ron Johnson 2024-06-19 21:02:19 Re: Transaction issue