Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id F365A63233F for ; Sun, 22 Aug 2010 12:55:59 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 94616-06 for ; Sun, 22 Aug 2010 15:55:52 +0000 (UTC) Received: from news.hub.org (news.hub.org [200.46.204.72]) by mail.postgresql.org (Postfix) with ESMTP id E76476322D1 for ; Sun, 22 Aug 2010 12:55:52 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.14.4/8.14.4) with ESMTP id o7MFtqWY001165 for ; Sun, 22 Aug 2010 12:55:52 -0300 (ADT) (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.14.4/8.14.4/Submit) id o7MFcPBZ091791 for pgsql-jdbc@postgresql.org; Sun, 22 Aug 2010 12:38:25 -0300 (ADT) (envelope-from news) From: Lew X-Newsgroups: pgsql.interfaces.jdbc Subject: Re: uuid values as parameters Date: Sun, 22 Aug 2010 11:38:36 -0400 Organization: albasani.net Lines: 39 Message-ID: References: <6922363a-ac17-49da-a5bd-ac5d03653dde@x42g2000yqx.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@albasani.net X-User-ID: RpfSDzvT8pnOHqnr/iye6YUrxhQjLYMu7PPICI9BufU= In-Reply-To: <6922363a-ac17-49da-a5bd-ac5d03653dde@x42g2000yqx.googlegroups.com> Cancel-Lock: sha1:BMq6cs00XsaG8ND36Q6oZpH7jaQ= User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.11) Gecko/20100713 Thunderbird/3.0.6 X-NNTP-Posting-Host: F/mN74hu9o8mWYruIj1n49Xd01Vgl53iBsRvgKAXZHI= To: pgsql-jdbc@postgresql.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.011 tagged_above=-10 required=5 tests=BAYES_40=-0.001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201008/64 X-Sequence-Number: 20867 On 08/19/2010 12:10 PM, vtkstef wrote: > Hi, > > I have a simple table foo with a column guid of data type uuid > > if I execute the following query > > select guid from foo where guid = '849b3d72-1400-44f1- > a965-1f4648475589' > > the query returns fine > > but if I parameterize the query as this > > select guid from foo where guid = ? > > and I set the the parameter using setString(1, '849b3d72-1400-44f1- > a965-1f4648475589') > > the query bombs with the following: > > [Error Code: 0, SQL State: 42883] ERROR: operator does not exist: > uuid = character varying > > I understand I need to use setObject(), or that I could explicitly > cast it (select guid from foo where guid = ?::uuid) but I don't > understand why harcoding a string works, and sending a string > parameter does not When you give the SQL parser a string literal, it knows that it might have to convert to the column type, and at that can only do so for column types that define a conversion for string literals. When you give the parser a parameter to a prepared statement, you are adding the feature of strong type safety. You are actually depending on the parser to reject inputs of the wrong type. For it to accept a string value for the parameter would be a violation of that trust. -- Lew