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.94.2) (envelope-from ) id 1qi8yS-005Imj-Nn for pgsql-odbc@arkaria.postgresql.org; Mon, 18 Sep 2023 07:47:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qi8yR-00FNie-8g for pgsql-odbc@arkaria.postgresql.org; Mon, 18 Sep 2023 07:47:15 +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.94.2) (envelope-from ) id 1qi4ho-00ELwy-V4 for pgsql-odbc@lists.postgresql.org; Mon, 18 Sep 2023 03:13:48 +0000 Received: from mail-yw1-x1130.google.com ([2607:f8b0:4864:20::1130]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qi4hm-005AsV-EY for pgsql-odbc@postgresql.org; Mon, 18 Sep 2023 03:13:47 +0000 Received: by mail-yw1-x1130.google.com with SMTP id 00721157ae682-59bd2e19c95so42885307b3.0 for ; Sun, 17 Sep 2023 20:13:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695006825; x=1695611625; darn=postgresql.org; h=content-transfer-encoding:content-language:mime-version:user-agent :date:message-id:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=gbJcIFdmfT2fV2MP6BiciJa3AN9LVM8FLIUTHOEUGGU=; b=iz+NKZFc+zjQPZFcJf3pw9KpDIEkT9WZ/dA1jM01KZRRLL3wQwmYkVhkj/nfD5L8HK Goxx1FHSdXOkq94h+PYhGLKmwjPhRx44UTzRqIkLLBHz6BYEi3TCfq785AR8PPxn7MhU vby9MmuCUolC66hgGNmaTsFkDEa2n9vVeZl4SygDH18rpdhdyGoel7G49GYLiB0rrCs+ cQV7jLc4WGEAsEprdUpJBAQCuSHsad2bjo7YiVChRQpyzihQ589vwr7Bfi9IoZoTiAPD D0aecCsNrvsAuQl3+hV32MZhbt6mDRCKL2EMKNFXiKIHGUUwLfVPlSTm6hnZRk75LIYj /Tag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695006825; x=1695611625; h=content-transfer-encoding:content-language:mime-version:user-agent :date:message-id:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gbJcIFdmfT2fV2MP6BiciJa3AN9LVM8FLIUTHOEUGGU=; b=K3R2WmTg5u08RoxQd+Q2yOVJLS9xU7MkCnMcZ4Qe9JTTq9Tf3UeSccZWL4V/VXgfGg ZMnkSYQI6geTVr3arTC/pjrN5Sj/2ftr5R4vt/Gn4rL3nMX3lHYHNq7ISLmNzDpVH+zM T0pIH2JHCAdrYFkHMp15u/yW9ytGS8FA9v28kZbCmwxkoc8q5Tx+RkMP2vChuKYOhAst VhMElAB9adQ6KHYNNVSt64eNJLW658uqI7ObLKB07iTruzkZhZl5K1Q4tl1NTqunfQT7 FGkI3XeXTuDUkWq2sVcQ96x0TCPQzOv2i+oCpy+9hnliYo5pCU52FlTbLbnOBd9Y9Un0 dmPw== X-Gm-Message-State: AOJu0YyN0ERCLqhDUoE6J2hvu4fOcQqLT75V3eXeyxSYp+XzBOQmTOjD lqu7djGQ4ke9ZGwcz97dnb/qPlGcCZE= X-Google-Smtp-Source: AGHT+IEr8AVUxwfNXckXpaVMr6C+ExFgJfbm3SIjcQt6S3aJbr1RFPTH0PhIF4Le0LEVEc2K+Lrckw== X-Received: by 2002:a81:5e84:0:b0:589:c065:b419 with SMTP id s126-20020a815e84000000b00589c065b419mr9889715ywb.34.1695006825530; Sun, 17 Sep 2023 20:13:45 -0700 (PDT) Received: from [174.161.63.214] (c-174-161-63-214.hsd1.tn.comcast.net. [174.161.63.214]) by smtp.gmail.com with ESMTPSA id l3-20020a0de203000000b005927a79333esm2265472ywe.28.2023.09.17.20.13.45 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 17 Sep 2023 20:13:45 -0700 (PDT) From: Hime Haieto X-Google-Original-From: Hime Haieto To: pgsql-odbc@postgresql.org Subject: handling of parametre types for prepared statements Message-ID: <075c30be-6254-c03e-e551-31018e0b664e@gmail.com> Date: Sun, 17 Sep 2023 23:13:44 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello everyone, I came across an issue where the data types for parametres of my prepared statements were not properly determined at the time of statement preparation, and that led to me investigating the matter a bit more closely. It seems as though the psqlODBC driver relies solely on inference to determine and set the types for positional parametres when preparing a statement, and sometimes this can fail, leading to a parametre getting the OID 0 and being treated as text. This can lead to errors later when binding variables prior to a given execution of the statement, and has no particularly satisfactory solution that I've found, save for taking the hit for reparsing and not using prepared statements in the first place. However, when looking into the matter, I noticed this text from the ODBC API reference: "Depending on the capabilities of the driver and data source, parameter information (such as data types) might be checked when the statement is prepared (if all parameters have been bound) or when it is executed (if all parameters have not been bound)." It seems as though the current (16.0) version of the driver does not do either of these, as if I attempt to bind all the parametres with their explicit type information prior to calling SQLPrepare, it still relies on the insufficient inferencing, and under no circumstances I've found will it defer this determination to its (first?) execution. The latter option seems as though it *might* not even be possible within the limits of libpq (save for deferring the actual statement preparation to the first execution, which might potentially be dubious), but the former should absolutely be doable. Thus, I have to wonder if there's a reason for why psqlODBC does not follow the specification's guidance as stated above, or if it's simply a matter of nobody having implemented it as such and could just be awaiting a patch? For reference, here is a simple query that can be problematic for an inference-only approach: with record as (values (5)) insert into mytable(someintvalue) select * from record;