Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XhMii-0005ev-1d for pgsql-bugs@arkaria.postgresql.org; Thu, 23 Oct 2014 18:02:44 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XhMig-0003Xo-DQ for pgsql-bugs@arkaria.postgresql.org; Thu, 23 Oct 2014 18:02:42 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Xh3N5-0005jU-7J for pgsql-bugs@postgresql.org; Wed, 22 Oct 2014 21:23:07 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xh3N0-0001Zz-UY for pgsql-bugs@postgresql.org; Wed, 22 Oct 2014 21:23:05 +0000 MIME-Version: 1.0 Subject: BUG #11767: ODBC driver bug when fetching constant string columns To: pgsql-bugs@postgresql.org From: keyurgovande@gmail.com Date: Wed, 22 Oct 2014 21:22:10 +0000 Message-ID: <20141022212210.2665.47909@wrigleys.postgresql.org> X-Pg-Spam-Score: -0.3 (/) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org The following bug has been logged on the website: Bug reference: 11767 Logged by: Keyur Govande Email address: keyurgovande@gmail.com PostgreSQL version: 9.0.3 Operating system: Centos 6.5 Description: Hello, This was reported to the PHP project (https://bugs.php.net/bug.php?id=68087) but it seems like a Postgres ODBC driver bug. If we run a SELECT statement like: SELECT id, varchar_col, date_col, 'random string' as random; via ODBC, then the last column comes back as junk into PHP. In PHP we use the SQL_DESC_OCTET_LENGTH to figure out how many bytes to allocate. But for that column, SQL_DESC_OCTET_LENGTH returns 0 and we don't allocate enough space. The driver issue seems to be that when SQLColAttributes() is called with SQL_COLUMN_TYPE for column 'random', it returns SQL_VARCHAR even though the PG type is PG_TYPE_UNKNOWN. The promotion is happening here: http://git.postgresql.org/gitweb/?p=psqlodbc.git;a=blob;f=pgtypes.c;h=4ce7636b69d371d9f511d492c68013f070e3b32a;hb=HEAD#l665 I think the same promotion needs to happen when fetching octet-length here: http://git.postgresql.org/gitweb/?p=psqlodbc.git;a=blob;f=pgtypes.c;h=4ce7636b69d371d9f511d492c68013f070e3b32a;hb=HEAD#l1275 Thoughts? This is not a problem when using the Vertica ODBC driver for example. A temporary workaround is to use a cast thusly: SELECT id, varchar_col, date_col, varchar 'random string' as random; -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs