Lists: | pgsql-novice |
---|
From: | ionFreeman(at)gmail(dot)com (Ion Chalmers Freeman) |
---|---|
To: | pgsql-novice(at)postgresql(dot)org |
Subject: | PREPARE function |
Date: | 2004-11-02 18:25:40 |
Message-ID: | e1fe5cb7.0411021025.3cdb496b@posting.google.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-novice |
So, I wrote a little function. Yay! I went to the dbExperts prompt
(I'm on Windows XP) and created it. Yay! Now, I'd like to run it.
> \i pg_MyFile.sql
this bit works great. But, the next bit, I'm having a problem with.
Say my function name was redefeat and it took one varchar.
> prepare redefeat(varchar);
doesn't work; nor does
> prepare vote (varchar) as redefeat;
or
> prepare(execute redefeat('Bush');
What is the syntax for prepare? The man page is not sufficiently clear
for me. Here it is:
http://www.postgresql.org/docs/7.4/interactive/sql-prepare.html
Please help! What would the syntax be?
Ion
From: | Michael Fuhr <mike(at)fuhr(dot)org> |
---|---|
To: | Ion Chalmers Freeman <ionFreeman(at)gmail(dot)com> |
Cc: | pgsql-novice(at)postgresql(dot)org |
Subject: | Re: PREPARE function |
Date: | 2004-11-08 05:37:46 |
Message-ID: | 20041108053746.GA29968@winnie.fuhr.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-novice |
On Tue, Nov 02, 2004 at 10:25:40AM -0800, Ion Chalmers Freeman wrote:
> Say my function name was redefeat and it took one varchar.
> > prepare redefeat(varchar);
> doesn't work; nor does
> > prepare vote (varchar) as redefeat;
> or
> > prepare(execute redefeat('Bush');
> What is the syntax for prepare? The man page is not sufficiently clear
> for me.
If you want to use a prepared statement then do this:
PREPARE plan_name (varchar) AS SELECT func_name($1);
EXECUTE plan_name ('some string');
If you just want to call the function once then SELECT should suffice:
SELECT func_name('some string');
--
Michael Fuhr
http://www.fuhr.org/~mfuhr/