X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B49FB9DCB71 for ; Tue, 7 Feb 2006 19:59:26 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 80053-10 for ; Tue, 7 Feb 2006 19:59:29 -0400 (AST) X-Greylist: delayed 00:59:12.247902 by SQLgrey- Received: from mica.fhcrc.org (MICA.FHCRC.ORG [140.107.152.12]) by postgresql.org (Postfix) with ESMTP id 9472B9DC93C for ; Tue, 7 Feb 2006 19:59:24 -0400 (AST) Received: from jade.fhcrc.org (JADE.FHCRC.ORG [140.107.42.223]) by mica.fhcrc.org (8.12.7/8.12.7/SuSE Linux 0.6) with ESMTP id k17NxOqq027780 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO); Tue, 7 Feb 2006 15:59:25 -0800 Received: from [140.107.157.114] (DHCP157114.FHCRC.ORG [140.107.157.114]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by jade.fhcrc.org (Postfix) with ESMTP id BD857E510; Tue, 7 Feb 2006 16:59:24 -0800 (PST) Message-ID: <43E9344C.2060805@bellew.net> Date: Tue, 07 Feb 2006 15:59:08 -0800 From: Matthew Bellew User-Agent: Mozilla Thunderbird 1.0.7 (Windows/20050923) X-Accept-Language: en-us, en MIME-Version: 1.0 Cc: Kris Jurka , pgsql-jdbc@postgresql.org Subject: Re: Inconsistent casting with literal vs parameter References: <43E91EFA.4080106@bellew.net> <43E9265E.3070209@bellew.net> In-Reply-To: <43E9265E.3070209@bellew.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-PMX-Version: 4.7.1.128075, Antispam-Engine: 2.2.0.0, Antispam-Data: 2006.02.06.102606 X-FHCRC-SCANNED: Tue Feb 7 15:59:25 2006 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.214 required=5 tests=[AWL=0.025, MISSING_HEADERS=0.189] X-Spam-Score: 0.214 X-Spam-Level: X-Archive-Number: 200602/48 X-Sequence-Number: 14645 I wrote the following code Properties props = new Properties(); props.put("user", "postgres"); props.put("password", "****"); props.put("stringtype", "unspecified"); Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost/cpas", props); DatabaseMetaData md = conn.getMetaData(); System.out.println("Server URL: " + md.getURL()); System.out.println("Database Product Name: " + md.getDatabaseProductName()); System.out.println("Database Product Version: " + md.getDatabaseProductVersion()); System.out.println("JDBC Driver Name: " + md.getDriverName()); System.out.println("JDBC Driver Version: " + md.getDriverVersion()); Unfortunately, it gives the same result. Server URL: jdbc:postgresql://localhost/cpas Database Product Name: PostgreSQL Database Product Version: 8.1.0 JDBC Driver Name: PostgreSQL Native Driver JDBC Driver Version: PostgreSQL 8.1 JDBC3 with SSL (build 404) So, does this mean this parameter is not properly respected in the driver? Matt Matthew Bellew wrote: > Fantastic, thanks for the pointer this parameter. I would argue that > the expected behavior would be that these two cases are semantically > equivalent. The fact that this is configurable is great, but my gripe > would be that the default setting results in 'wrong' answers for a > very unobvious reason. > > Again thanks, > Matt > > Kris Jurka wrote: > >> >> >> On Tue, 7 Feb 2006, Matthew Bellew wrote: >> >>> I have an example here where replacing a string literal with a >>> string parameter in the same query yields different results. See >>> Java code below, and note that this example works with int as well >>> as float. In one case the comparisions are done as numbers in the >>> other they are done as strings. The explanation I received from Tom >>> Lane is that in stmtA with (x < '100'), '100' is an untyped literal, >>> in stmtB and stmtC (x < ?), the parameter is treated as typed, and >>> thus the coercion occurs differently. I'm afraid someone is going >>> to answer "it works this way because..." I'm more interested to >>> know if anyone else thinks it is a problem that these two statements >>> return different results. I seems to me that these queries >>> reasonably have to be considered the same, and should return the >>> same answer.. >> >> >> >> I don't think these queries are the same, consider >> SELECT '12' < '2', 12 < 2; >> >> In the first case the server considers it text and the second it >> considers it numeric. Now when considering the mixed case the server >> has to decide what to do. When you say 12 < '2' you aren't >> conclusively stating what type '2' is and it gets coerced to numeric, >> but when you say setString you are explicitly telling it that it is a >> text data type and a text comparison should be done. When you say >> setObject with a String object you also say that it is text data. If >> you want it interpreted as numeric data use setFloat or similar. >> >> The 8.2 driver has an option to allow setString data to passed to the >> server without a type and you will get the result you desire. See >> the stringtype parameter here: >> >> http://jdbc.postgresql.org/documentation/head/connect.html#connection-parameters >> >> >> Kris Jurka >> >> ---------------------------(end of broadcast)--------------------------- >> TIP 6: explain analyze is your friend > > > > ---------------------------(end of broadcast)--------------------------- > TIP 6: explain analyze is your friend