Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vVyk6-00AFdH-2O for pgsql-general@arkaria.postgresql.org; Wed, 17 Dec 2025 21:07:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vVyk4-00GTnf-0L for pgsql-general@arkaria.postgresql.org; Wed, 17 Dec 2025 21:07:28 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vVyk3-00GTnW-2D for pgsql-general@lists.postgresql.org; Wed, 17 Dec 2025 21:07:28 +0000 Received: from mail-yx1-xb12d.google.com ([2607:f8b0:4864:20::b12d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vVyk2-001DKJ-2k for pgsql-general@lists.postgresql.org; Wed, 17 Dec 2025 21:07:27 +0000 Received: by mail-yx1-xb12d.google.com with SMTP id 956f58d0204a3-64475c16a11so7359641d50.1 for ; Wed, 17 Dec 2025 13:07:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766005646; x=1766610446; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=4PzAhLcDMssbNEUP+eYdctLhnF5mSNfMiE/UaTO0OMA=; b=lONsgkZP41iRFs6vjDjqce7bosxEVrmKJ/lq9FjoSnetyvClIy3BctIctqqYzH8dRX cTePQlu3YtBYSUA5hlMC1u8q3ovU2As+xp1l0jBtc4vOHjA3RhyODULL0Iw81sGNO75/ gO7t/VMeKob9gP5DXJ2uaBNo5VTkcvwyJPSzjFi9R7tWwILb+2zRrGHDr5c5ut9Pq8ui XnOrRVAGe4ATBEti2kLeHNi1w+nVxfjlvUGe67Rzd/vcjO+zc78qDWisJitI26YI3gcW UpZ/P11D3ogEVax+1wXdvvEWCzxx2Qunxt84sqVMourb5g6kBXXlMlzPr6DP5pIYsI4G y9/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766005646; x=1766610446; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=4PzAhLcDMssbNEUP+eYdctLhnF5mSNfMiE/UaTO0OMA=; b=hJ2D9Khb1HzfGJcFgtMhmrsEaH3sWQTwEUSM0j1+4SZgW+VhvkY1oIsbeVdE0zgWPo kkAaQ8nbdKQPUrPgUAhYvY82e/Dqm2W9Li1voBQhOsgLws+kvcbSD5pY0+nxTlFDFgDH wJDyYzN6OQxh/mC8olOpzwSKaUyx53KRnH/WlrsWYpJfcn1gKA2DeLrawlWNoPW/SzlQ ctpY1hwEjtUrrUxKj4SBJz1qixOKPSt+kQFGoYrHYs/te4gOAgB5kNR/4XpmAWGMFxhu d74ewHGyWJaFFA4ZiVbapfAEMwT6RBpIw6WX3+o9H1B32w3vAl57VZoi9WjFFuS7ESC1 h4jg== X-Gm-Message-State: AOJu0YxyCqxCwYKOWCE12HMRsMogb40k7SwlmbLUPaT6hCbQP5RE8Cbu BQZT/GMJsmMJb4r7qHWTerl6slssP5Oa19mmUzVUIe6wM5b2AKHTmwd4ddIO/GhB6SMmE1bLNvy zrrIV5wvO+McpvWgB1f6gZvtbBz92QPHtmUQIHbc= X-Gm-Gg: AY/fxX55Y+msYvUcG3MY6nVZVzmULVQ3DH/72SVM2tTqdMkTaw7z/KxJQhnQcqyZUeA 35Kr50cKF7aEQrwqiQPEuHG0YLa18UtTXZz+UYmEPKphREU0OTMN4iGeKLZHblnm2OsN3SzNeci ZKr8C31ohn/0GDldKqQy6PkTnOr+qhxg9yUqLQE2/CbN+SE6lHW+x1pz+l+QQclGlsZrhhyqvgl LoFsbMTz1jUwTQSYt1V5Xs/+frPg+PpBKJ/8wi3CBlrNT2WR1CaQVNEL1IM5tkqC2LQ8owvBBsH BW8OYjM8levA15HXhTz24jf1NKHVwlFsQYJIbQ== X-Google-Smtp-Source: AGHT+IFXlaraHrWfpDgd7jtRy27kyN6EBMSncN8KOjlTfxxSuXT6lPmYldC48coUMtC3t/UPbpmG32Hu/jE0exACxKY= X-Received: by 2002:a05:690e:4087:b0:645:5d39:2543 with SMTP id 956f58d0204a3-6455d3937c7mr12541712d50.19.1766005645576; Wed, 17 Dec 2025 13:07:25 -0800 (PST) MIME-Version: 1.0 References: <3fd9c2859c323d6f894ccf660764f24dc3423181.camel@cybertec.at> In-Reply-To: <3fd9c2859c323d6f894ccf660764f24dc3423181.camel@cybertec.at> From: Igor Korot Date: Wed, 17 Dec 2025 13:07:22 -0800 X-Gm-Features: AQt7F2ol0_FasrZU9tVM_yeeiIv26g0-kUamhZa1Ox5rrUt0DFWpX23ClXVz6DM Message-ID: Subject: Re: libpq simple SELECT To: Laurenz Albe Cc: "pgsql-generallists.postgresql.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Laurenz, On Wed, Dec 17, 2025 at 12:22=E2=80=AFPM Laurenz Albe wrote: > > On Wed, 2025-12-17 at 09:42 -0800, Igor Korot wrote: > > On Tue, Dec 16, 2025 at 11:34=E2=80=AFPM Laurenz Albe wrote: > > > On Tue, 2025-12-16 at 21:49 -0800, Igor Korot wrote: > > > > I just tried the following code: > > > > > > > > [code] > > > > std::wstring query1 =3D 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 =3D > > > > c.relname AND c.relowner =3D usesysid AND (t.table_type =3D 'BASE T= ABLE' > > > > OR t.table_type =3D 'VIEW' OR t.table_type =3D 'LOCAL TEMPORARY') O= RDER BY > > > > table_name;"; > > > > res =3D PQexec( m_db, m_pimpl->m_myconv.to_bytes( query1.c= _str() > > > > ).c_str() ); > > > > for( int i =3D 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 r= equired. > > I am still confused. > > You quoted a comment from a sample program in the documentation, and that > example is actually using a cursor: > > res =3D PQexec(conn, "DECLARE myportal CURSOR FOR select * from pg_da= tabase"); > > But your code does not use a cursor. So why should the comment apply to = it? This is a comment: /* * Our test case here involves using a cursor, for which we must be ins= ide * a transaction block. We could do the whole thing with a single * PQexec() of "select * from pg_database", but that's too trivial to m= ake * a good example. */ When I read it my understanding is: It is possible to write the code without a cursor.. However it will be trivial and so the code will use CURSOR. But the usage of CURSOR is actually not required - it is used in the docs only to make a good example. However, when I tried to write the code without the CURSOR it seems that CURSOR usage is a must and not optional, which contradicts the comment above. I hope now my question is clear. I want to know if using CURSR is a must. Thank you. > > Yours, > Laurenz Albe