Thread: Prepared statements question

Prepared statements question

From
"Christopher Kings-Lynne"
Date:
Hi,

With prepared statements being all well and good, how do I know if the query
has not yet been prepared in the backend?  Or is this simply a situation
where I can't win?

eg. Say I have a web page that does a humungous query.  I would like to have
that query prepared, say, for speed.  However, I can't tell if that backend
has had that query prepared or not.  Is there any way around this?

Chris



Re: Prepared statements question

From
"Christopher Kings-Lynne"
Date:
I guess I should just use a stored procedure...

Chris

> -----Original Message-----
> From: pgsql-hackers-owner@postgresql.org
> [mailto:pgsql-hackers-owner@postgresql.org]On Behalf Of Christopher
> Kings-Lynne
> Sent: Friday, 10 January 2003 11:48 AM
> To: Hackers
> Subject: [HACKERS] Prepared statements question
> 
> 
> Hi,
> 
> With prepared statements being all well and good, how do I know 
> if the query
> has not yet been prepared in the backend?  Or is this simply a situation
> where I can't win?
> 
> eg. Say I have a web page that does a humungous query.  I would 
> like to have
> that query prepared, say, for speed.  However, I can't tell if 
> that backend
> has had that query prepared or not.  Is there any way around this?
> 
> Chris
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
> 



Re: Prepared statements question

From
Neil Conway
Date:
On Thu, 2003-01-09 at 22:48, Christopher Kings-Lynne wrote:
> With prepared statements being all well and good, how do I know if the query
> has not yet been prepared in the backend?  Or is this simply a situation
> where I can't win?

Try the EXECUTE; if it fails, run the PREPARE and then rerun the
EXECUTE.

It would be pretty trivial to add a function that checks if a query with
a given name has already been prepared -- is that worth doing?

Cheers,

Neil



Re: Prepared statements question

From
Kevin Brown
Date:
Neil Conway wrote:
> On Thu, 2003-01-09 at 22:48, Christopher Kings-Lynne wrote:
> > With prepared statements being all well and good, how do I know if the query
> > has not yet been prepared in the backend?  Or is this simply a situation
> > where I can't win?
> 
> Try the EXECUTE; if it fails, run the PREPARE and then rerun the
> EXECUTE.

Erm...won't the failed EXECUTE boot you out of the middle of a
transaction?  The documentation doesn't make it clear what happens in
that case, and I don't have 7.3.x running to check for myself...



-- 
Kevin Brown                          kevin@sysexperts.com


Re: Prepared statements question

From
"Christopher Kings-Lynne"
Date:
OK, how about a backend function called 'is_prepared(name)'?

Chris

> -----Original Message-----
> From: pgsql-hackers-owner@postgresql.org
> [mailto:pgsql-hackers-owner@postgresql.org]On Behalf Of Kevin Brown
> Sent: Monday, 13 January 2003 11:13 AM
> To: PostgreSQL Hackers
> Subject: Re: [HACKERS] Prepared statements question
> 
> 
> Neil Conway wrote:
> > On Thu, 2003-01-09 at 22:48, Christopher Kings-Lynne wrote:
> > > With prepared statements being all well and good, how do I 
> know if the query
> > > has not yet been prepared in the backend?  Or is this simply 
> a situation
> > > where I can't win?
> > 
> > Try the EXECUTE; if it fails, run the PREPARE and then rerun the
> > EXECUTE.
> 
> Erm...won't the failed EXECUTE boot you out of the middle of a
> transaction?  The documentation doesn't make it clear what happens in
> that case, and I don't have 7.3.x running to check for myself...
> 
> 
> 
> -- 
> Kevin Brown                          kevin@sysexperts.com
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
> 
> http://www.postgresql.org/users-lounge/docs/faq.html
>