Re: SQL function problem in 7.1?

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Richard Huxton <dev(at)archonet(dot)com>
Cc: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: SQL function problem in 7.1?
Date: 2001-02-09 17:42:59
Message-ID: Pine.BSF.4.21.0102090941430.59316-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


You don't want to quote the $1. Otherwise you're going to probably
get the literal '$1'.

create function foob(text) returns int as 'select a from foo
where b = $1;' language'sql';

(the space before the $ is significant)

Stephan Szabo
sszabo(at)bigpanda(dot)com

On Fri, 9 Feb 2001, Richard Huxton wrote:

> Am I doing something stupid with strings in SQL functions.
>
>
> richardh=> select version();
> version
> ------------------------------------------------------------------------
> PostgreSQL 7.1beta3 on i586-pc-linux-gnu, compiled by GCC egcs-2.91.66
> (1 row)
>
> richardh=> select * from foo;
> a | b
> ---+-----
> 1 | aaa
> 2 | bbb
> 3 | ccc
> (3 rows)
>
> richardh=> create function fooa(int) returns text as 'select b from foo
> where a = $1;' language 'sql';
> CREATE
> richardh=> select fooa(2);
> fooa
> ------
> bbb
> (1 row)
>
> richardh=> create function foob(text) returns int as 'select a from foo
> where b = ''$1'';' language 'sql';
> CREATE
> richardh=> select foob('bbb');
> foob
> ------
>
> (1 row)
>
>
> TIA
>
> - Richard Huxton
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Kogotkov, Vyacheslav 2001-02-09 18:58:13 can't run pg_dump in sh script using crontab
Previous Message Tom Lane 2001-02-09 17:36:56 Re: Starting postmaster in logging mode