Re: RQ: Prepared statements used by multiple connections - Mailing list pgsql-hackers

From Christopher Kings-Lynne
Subject Re: RQ: Prepared statements used by multiple connections
Date
Msg-id 41F61367.5060807@familyhealth.com.au
Whole thread Raw
In response to RQ: Prepared statements used by multiple connections  (Bojidar Mihajlov <bmihajlov@yahoo.com>)
Responses Re: RQ: Prepared statements used by multiple connections  (Neil Conway <neilc@samurai.com>)
List pgsql-hackers
> I need a mechanism to keep my queries in optimized
> state so that multiple processes can use them.

You should use stored procedures then.

For instance, say you want to keep 'SELECT * FROM table WHERE id=x'
prepared.  You would go:

CREATE OR REPLACE FUNCTION get_table_id(integer) RETURNS SETOF table AS
'SELECT * FROM table WHERE id=$1' LANGUAGE SQL;

PostgreSQL will store a prepared version of that statement after its
first use.

You use it like this:

SELECT * FROM get_table_id(3);

Chris

pgsql-hackers by date:

Previous
From: Bojidar Mihajlov
Date:
Subject: RQ: Prepared statements used by multiple connections
Next
From: Neil Conway
Date:
Subject: Re: RQ: Prepared statements used by multiple connections