Re: Prepared statements and unknown types - Mailing list pgsql-general

From Thom Brown
Subject Re: Prepared statements and unknown types
Date
Msg-id AANLkTi=4oR34QtSycOUOD82_L8QHpQLd6rRvmBCVuMNC@mail.gmail.com
Whole thread Raw
In response to Re: Prepared statements and unknown types  (Peter Bex <Peter.Bex@xs4all.nl>)
List pgsql-general
On 29 September 2010 19:41, Peter Bex <Peter.Bex@xs4all.nl> wrote:
> On Wed, Sep 29, 2010 at 07:33:53PM +0100, Thom Brown wrote:
>> Okay, I understand what's happening.  But does the planner need to
>> understand the type of literals in the select list if it's not used
>> anywhere else?
>
> Fields sent back to the client also carry their type with them.
> There's no "unknown" type (and it wouldn't be very useful in any
> case, because how would you go about displaying an unknown type?)

There is an unknown type...

test=# create table stuff (id serial);
NOTICE:  CREATE TABLE will create implicit sequence "stuff_id_seq" for
serial column "stuff.id"
CREATE TABLE

test=# insert into stuff select c from generate_series(1,100) x(c);
INSERT 0 100

test=# PREPARE meow(unknown) AS
SELECT * from stuff where id < $1;
PREPARE
test=# execute meow(3);
 id
----
  1
  2
(2 rows)

test=# PREPARE bark(unknown) AS
SELECT * from stuff where id < $1;
PREPARE
test=# execute bark('3'::unknown);
 id
----
  1
  2
(2 rows)

The docs specifically make mention of it in the case of PREPARE.
--
Thom Brown
Twitter: @darkixion
IRC (freenode): dark_ixion
Registered Linux user: #516935

pgsql-general by date:

Previous
From: Peter Bex
Date:
Subject: Re: Prepared statements and unknown types
Next
From: sunpeng
Date:
Subject: Are there any commands to see the created index info?