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 1vyq1s-000Sz2-2h for pgsql-odbc@arkaria.postgresql.org; Sat, 07 Mar 2026 11:41:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vyq1r-008VEh-0g for pgsql-odbc@arkaria.postgresql.org; Sat, 07 Mar 2026 11:41:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vyq1q-008VEZ-37 for pgsql-odbc@lists.postgresql.org; Sat, 07 Mar 2026 11:41:07 +0000 Received: from pgintl.fastcrypt.com ([149.56.129.164]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vyq1n-00000001L4V-0CUD for pgsql-odbc@postgresql.org; Sat, 07 Mar 2026 11:41:06 +0000 Received: from mail-ot1-f42.google.com (mail-ot1-f42.google.com [209.85.210.42]) by pgintl.fastcrypt.com (Postfix) with ESMTPSA id A627A2022E for ; Sat, 7 Mar 2026 06:40:59 -0500 (EST) Received: by mail-ot1-f42.google.com with SMTP id 46e09a7af769-7d4ba9abbecso12041204a34.1 for ; Sat, 07 Mar 2026 03:40:59 -0800 (PST) X-Gm-Message-State: AOJu0Yz/axg3XaQOaBBerfi9N4urO5XBJ5VpB2rpe8M/olZfKVTodmbn WFQjANUjJIazkLaZOFxAx+i4DvwrFqijr30LwgVEkUgfqv6M9B6wpDHuG5i5YfIjvaAhMrAEPgH fPJu1Fzwe93PBBy2LRidtGBgaACJVRH8= X-Received: by 2002:a05:6820:4dc8:b0:67a:61f:646b with SMTP id 006d021491bc7-67b9bd78acamr2833725eaf.74.1772883658966; Sat, 07 Mar 2026 03:40:58 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Dave Cramer Date: Sat, 7 Mar 2026 06:40:43 -0500 X-Gmail-Original-Message-ID: X-Gm-Features: AaiRm52Ym9QWQVXj4scWDxMEj0S9o2nBYJFkGSU2cFViOiWWzMTAhLwKaBQzV7w Message-ID: Subject: Re: How to properly perform this? To: Igor Korot Cc: PostgreSQL ODBC list Content-Type: multipart/alternative; boundary="000000000000b88ccb064c6da4da" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000b88ccb064c6da4da Content-Type: text/plain; charset="UTF-8" Dave Cramer www.postgres.rocks On Sat, 7 Mar 2026 at 01:10, Igor Korot wrote: > Hi, ALL, > I'm trying to execute following query: > > draft=# SELECT c.relname AS name, ixs.tablespace, ARRAY(SELECT > a.attname FROM pg_attribute a WHERE a.attrelid = idx.indrelid AND > a.attnum = ANY(idx.indkey) AND a.attnum > 0 ORDER BY > array_position(idx.indkey, a.attnum) OFFSET idx.indnkeyatts) AS > included, c.reloptions AS storage FROM pg_index idx, pg_class c, > pg_namespace n, pg_class t, pg_indexes ixs WHERE ixs.indexname = > c.relname AND c.oid = idx.indexrelid AND t.oid = idx.indrelid AND > n.oid = c.relnamespace AND idx.indisprimary AND n.nspname = 'public' > AND t.relname = 'leagues'; > name | tablespace | included | storage > --------------+------------+----------+--------- > leagues_pkey | | {} | > (1 row) > > > My code is as follows: > > while( ( ret = SQLGetData( m_hstmt, 4, SQL_C_WCHAR, > index_param.get(), 255, &ind[3] ) ) != SQL_NO_DATA ) > { > if( ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO ) > { > auto numBytes = ind[3]; > if( ind[3] == SQL_NO_TOTAL ) > numBytes = 255; > else if( ind[3] > 255 ) > numBytes = 255; > str_to_uc_cpy( options, index_param.get() ); > } > else > { > GetErrorMessage( errorMsg, STMT_ERROR ); > result = 1; > } > } > Unfortunately it goes into the loop because apparently the driver or > the server keeps seeing the last column as having data and returns > SQL_SUCCESS. > > What is the proper way to resolve this? > > I'm using unixODBC with PostgreSQL 16. > > My odbc.ini looks like this: > > [code] > [postgres] > Driver=Postgres > Description=Postgres ODBC Driver > UserId=postgres > Password=XXX > Servername=localhost > Database=draft > Port=5432 > > [/code] > > > What is the best way to proceed? > is the last column empty or null? if not null then there is data there. Dave --000000000000b88ccb064c6da4da Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Dave Cramer
www.po= stgres.rocks


On Sat, 7 Mar= 2026 at 01:10, Igor Korot <ikorot= 01@gmail.com> wrote:
Hi, ALL,
I'm trying to execute following query:

draft=3D# SELECT c.relname AS name, ixs.tablespace, ARRAY(SELECT
a.attname FROM pg_attribute a WHERE a.attrelid =3D idx.indrelid AND
a.attnum =3D ANY(idx.indkey) AND a.attnum > 0 ORDER BY
array_position(idx.indkey, a.attnum) OFFSET idx.indnkeyatts) AS
included, c.reloptions AS storage FROM pg_index idx, pg_class c,
pg_namespace n, pg_class t, pg_indexes ixs WHERE ixs.indexname =3D
c.relname AND c.oid =3D idx.indexrelid AND t.oid =3D idx.indrelid AND
n.oid =3D c.relnamespace AND idx.indisprimary AND n.nspname =3D 'public= '
AND t.relname =3D 'leagues';
=C2=A0 =C2=A0 =C2=A0name=C2=A0 =C2=A0 =C2=A0| tablespace | included | stora= ge
--------------+------------+----------+---------
=C2=A0leagues_pkey |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | {}=C2=A0 = =C2=A0 =C2=A0 =C2=A0|
(1 row)


My code is as follows:

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 while( ( ret =3D SQLGetData( m_hs= tmt, 4, SQL_C_WCHAR,
index_param.get(), 255, &ind[3] ) ) !=3D SQL_NO_DATA )
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if( ret =3D=3D SQL_= SUCCESS || ret =3D=3D SQL_SUCCESS_WITH_INFO )
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 auto = numBytes =3D ind[3];
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if( i= nd[3] =3D=3D SQL_NO_TOTAL )
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 numBytes =3D 255;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 else = if( ind[3] > 255 )
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 numBytes =3D 255;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 str_t= o_uc_cpy( options, index_param.get() );
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 else
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 GetEr= rorMessage( errorMsg, STMT_ERROR=C2=A0 );
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 resul= t =3D 1;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
Unfortunately it goes into the loop because apparently the driver or
the server keeps seeing the last column as having data and returns
SQL_SUCCESS.

What is the proper way to resolve this?

I'm using unixODBC with PostgreSQL 16.

My odbc.ini looks like this:

[code]
[postgres]
Driver=3DPostgres
Description=3DPostgres ODBC Driver
UserId=3Dpostgres
Password=3DXXX
Servername=3Dlocalhost
Database=3Ddraft
Port=3D5432

[/code]


What is the best way to proceed?

is the= last column empty or null?

if not null then there= is data there.

Dave
--000000000000b88ccb064c6da4da--