From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Igor Korot <ikorot01@gmail.com>
To: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Can't query system tables during transaction
Date: Sun, 4 Oct 2020 13:24:49 -0700
Message-ID: <2c36acfd-d3c4-8929-5343-ddc07093adc6@aklaver.com> (raw)
In-Reply-To: <CA+FnnTyiz8i86MAVWriL4wzC1iSiZvqGjUpAMHiZoP+4cZNE1Q@mail.gmail.com>
References: <CA+FnnTyiz8i86MAVWriL4wzC1iSiZvqGjUpAMHiZoP+4cZNE1Q@mail.gmail.com>
On 10/4/20 1:14 PM, Igor Korot wrote:
> Hi, ALL,
> I'm trying to execute following:
>
> SELECT 1 FROM pg_class c, pg_namespace n WHERE n.oid = c.relnamespace
> AND c.relname = 'foo' AND n.nspname = public;
>
> inside the transaction.
>
> I'm getting the following error:
>
> ERROR: current transaction is aborted, commands ignored until end of
> transaction block
No it means another statement before this one threw an error and the
transaction needs to be rolled back. Something like this:
track_stocks(5442)=> begin ;
BEGIN
track_stocks(5442)=> SELECT 1 FROM pg_class c, pg_namespace n WHERE
n.oid = c.relnamespace
AND c.relname = 'stock-info' AND n.nspname = public;
ERROR: column "public" does not exist
LINE 2: AND c.relname = 'stock-info' AND n.nspname = public;
^
track_stocks(5442)=> SELECT 1 FROM pg_class c, pg_namespace n WHERE
n.oid = c.relnamespace
AND c.relname = 'stock-info' AND n.nspname = 'public';
ERROR: current transaction is aborted, commands ignored until end of
transaction block
track_stocks(5442)=> rollback ;
ROLLBACK
And now the correct query(Note the quoted schema name):
track_stocks(5442)=> begin ;
BEGIN
track_stocks(5442)=> SELECT 1 FROM pg_class c, pg_namespace n WHERE
n.oid = c.relnamespace
AND c.relname = 'stock-info' AND n.nspname = 'public';
?column?
----------
(0 rows)
>
> Does this mean I can't query system tables during the transaction?
> What is the problem here if it's not and how do I find out the reason?
> And if it is - how to work around it?
>
> I can probably commit it and start a new transaction, but I fear I will
> have the same issue there...
>
> Thank you.
>
> If it matters - I'm working with C++ and libpq.
>
>
--
Adrian Klaver
adrian.klaver@aklaver.com
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: adrian.klaver@aklaver.com, ikorot01@gmail.com
Subject: Re: Can't query system tables during transaction
In-Reply-To: <2c36acfd-d3c4-8929-5343-ddc07093adc6@aklaver.com>
References: <CA+FnnTyiz8i86MAVWriL4wzC1iSiZvqGjUpAMHiZoP+4cZNE1Q@mail.gmail.com> <2c36acfd-d3c4-8929-5343-ddc07093adc6@aklaver.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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