Re: sql insert function

From: Richard Welty <rwelty(at)averillpark(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: sql insert function
Date: 2004-01-13 00:35:43
Message-ID: Mahogany-0.66.0-1446-20040112-193543.00@averillpark.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 12 Jan 2004 16:21:17 -0800 Chris Ochs <chris(at)paymentonline(dot)com> wrote:

> The documentation doesn't have any examples of using an sql language
> function to do an insert, andI am at loss as to I am doing wrong here.
> The error I get trying to create the function is: ERROR: syntax error at
> or near "$1" at character 148

> CREATE FUNCTION taxship(varchar,integer,varchar,float,float) returns integer
> AS '
> insert into taxship(s_oid,order_id,mer_id,tax,shipping) values
> ('$1',$2,'$3',$4,$5);
> SELECT 1;
> ' LANGUAGE SQL;

i do believe you need to double up the single quotes inside the
function body, e.g.

(''$1'',$2,''$3'',$4,$5);

otherwise, the quote before the $1 ends up terminating the
function body.

richard
--
Richard Welty rwelty(at)averillpark(dot)net
Averill Park Networking 518-573-7592
Java, PHP, PostgreSQL, Unix, Linux, IP Network Engineering, Security

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Doug McNaught 2004-01-13 00:35:53 Re: sql insert function
Previous Message Alex Satrapa 2004-01-13 00:33:54 Re: sql insert function