X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id D1B619F9CAA for ; Wed, 14 Jun 2006 10:12:48 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 94848-08 for ; Wed, 14 Jun 2006 10:12:39 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from mail.gmx.net (mail.gmx.net [213.165.64.21]) by postgresql.org (Postfix) with SMTP id 636119FA5D8 for ; Wed, 14 Jun 2006 10:12:39 -0300 (ADT) Received: (qmail invoked by alias); 14 Jun 2006 13:12:37 -0000 Received: from dslb-084-057-019-157.pools.arcor-ip.net (EHLO ltmku) [84.57.19.157] by mail.gmx.net (mp034) with SMTP; 14 Jun 2006 15:12:37 +0200 X-Authenticated: #23352258 From: "Milen Kulev" To: Subject: Prepared statements in PGSQL functions Date: Wed, 14 Jun 2006 15:12:36 +0200 Message-ID: <010a01c68fb4$34db9990$0a00a8c0@trivadis.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.6626 Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 X-Y-GMX-Trusted: 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/155 X-Sequence-Number: 25391 Hi Listers, I want to use prepared statement in a function. Here is my code: create or replace function generate_data ( integer, integer ) returns integer as $BODY$ declare p_count alias for $1; p_max_value_id1 alias for $2; v_max_value_id1 integer ; v_id1 int; v_id2 int; v_filler varchar(200) := repeat('BIGSTRING', 3); begin v_id1:= round( (random()* v_max_value_id1)::bigint,0); v_id2:= round( (random()* v_max_value_id1)::bigint,0); prepare mystmt( int, int, varchar) as insert into part values ($1,$2,$3); execute mystmt(v_id1, v_id2, v_filler ); deallocate mystmt; end; $BODY$ language plpgsql ; Definition of table part is : CREATE TABLE part ( id1 int not null, id2 int not null, filler varchar(200) ); When I try to call my function I am getting the following errors : postgres=# select * from gen (10, 10 ); ERROR: function mystmt(integer, integer, character varying) does not exist HINT: No function matches the given name and argument types. You may need to add explicit type casts. CONTEXT: SQL statement "SELECT mystmt( $1 , $2 , $3 )" PL/pgSQL function "gen" line 12 at execute statement How to solve my problem ? Is it possible at all to call prepared statement inside a function at all? Regards. MILEN