Re: libpq simple SELECT

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Igor Korot <ikorot01(at)gmail(dot)com>
Cc: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: libpq simple SELECT
Date: 2025-12-17 20:22:32
Message-ID: 3fd9c2859c323d6f894ccf660764f24dc3423181.camel@cybertec.at
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, 2025-12-17 at 09:42 -0800, Igor Korot wrote:
> On Tue, Dec 16, 2025 at 11:34 PM Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> wrote:
> > On Tue, 2025-12-16 at 21:49 -0800, Igor Korot wrote:
> > > I just tried the following code:
> > >
> > > [code]
> > >      std::wstring query1 = L"SELECT t.table_catalog AS catalog,
> > > t.table_schema AS schema, t.table_name AS table, u.usename AS owner,
> > > c.oid AS table_id FROM information_schema.tables t,
> > > pg_catalog.pg_class c, pg_catalog.pg_user u WHERE t.table_name =
> > > c.relname AND c.relowner = usesysid AND (t.table_type = 'BASE TABLE'
> > > OR t.table_type = 'VIEW' OR t.table_type = 'LOCAL TEMPORARY') ORDER BY
> > > table_name;";
> > >          res = PQexec( m_db, m_pimpl->m_myconv.to_bytes( query1.c_str()
> > > ).c_str() );
> > >           for( int i = 0; i < PQntuples( res ); i++ )
> > >           {
> > > some code handling the results
> > >           }
> > > [/code]
> > >
> > > The loop is executed exactly 1 time.
> > >
> > > My question is - according to the comment above I don't have to use cursor,
> > > but it looks like it's unavoidable?
> >
> > I see no cursor in your example...
>
> That is my question.
>
> The code shows cursor but the comment indicate that the cursor is not required.

I am still confused.

You quoted a comment from a sample program in the documentation, and that
example is actually using a cursor:

res = PQexec(conn, "DECLARE myportal CURSOR FOR select * from pg_database");

But your code does not use a cursor. So why should the comment apply to it?

Yours,
Laurenz Albe

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Igor Korot 2025-12-17 21:07:22 Re: libpq simple SELECT
Previous Message Tom Lane 2025-12-17 18:37:34 Re: Record last SELECT on a row?