Prepared statements question

Started by Christopher Kings-Lynneabout 23 years ago5 messages
#1Christopher Kings-Lynne
chriskl@familyhealth.com.au

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

#2Christopher Kings-Lynne
chriskl@familyhealth.com.au
In reply to: Christopher Kings-Lynne (#1)
Re: Prepared statements question

I guess I should just use a stored procedure...

Chris

Show quoted text

-----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

#3Neil Conway
neilc@samurai.com
In reply to: Christopher Kings-Lynne (#1)
Re: Prepared statements question

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

#4Kevin Brown
kevin@sysexperts.com
In reply to: Neil Conway (#3)
Re: 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

#5Christopher Kings-Lynne
chriskl@familyhealth.com.au
In reply to: Kevin Brown (#4)
Re: Prepared statements question

OK, how about a backend function called 'is_prepared(name)'?

Chris

Show quoted text

-----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