X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 30ADF329E58; Sat, 11 Sep 2004 07:03:37 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 01988-08; Sat, 11 Sep 2004 06:03:31 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id C3E21329C65; Sat, 11 Sep 2004 07:03:31 +0100 (BST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i8B63UO8007436; Sat, 11 Sep 2004 02:03:30 -0400 (EDT) To: the inquirer Cc: pgsql-general@postgresql.org, pgsql-novice@postgresql.org, pgsql-sql@postgresql.org Subject: Re: PL/pgSQL Function Problem In-reply-to: <20040909174926.81383.qmail@web53002.mail.yahoo.com> References: <20040909174926.81383.qmail@web53002.mail.yahoo.com> Comments: In-reply-to the inquirer message dated "Thu, 09 Sep 2004 10:49:26 -0700" Date: Sat, 11 Sep 2004 02:03:30 -0400 Message-ID: <7435.1094882610@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.3 tagged_above=0.0 required=5.0 tests=UPPERCASE_25_50 X-Spam-Level: X-Archive-Number: 200409/525 X-Sequence-Number: 65731 the inquirer writes: > I am trying to create a function that creates a user > and adds a row to a table. It produces no warnings or > errors when I create the function but when I attempt > to execute it I get a syntax error. I do not > understand why this is happening. > CREATE OR REPLACE FUNCTION create_author ( > VARCHAR(32), VARCHAR(32), VARCHAR(32) ) > RETURNS INTEGER AS ' > DECLARE > name_ ALIAS FOR $1; > username_ ALIAS FOR $2; > password_ ALIAS FOR $3; > authorid_ INTEGER; > BEGIN > CREATE USER username_ WITH ENCRYPTED PASSWORD > password_ IN GROUP authors; Utility statements (which is to say anything except SELECT/INSERT/ UPDATE/DELETE) generally don't cope with parameters. The above won't work because it's trying to substitute parameters for username_ and password_ in the CREATE USER utility statement. You could make it work by constructing the CREATE USER command as a string and then EXECUTE'ing it. (I agree this ain't ideal, but it's where we're at...) regards, tom lane