Re: Dynamic SQL in function

From: Doug McNaught <doug(at)wireboard(dot)com>
To: robert(dot)goodwin(at)ums(dot)msfc(dot)nasa(dot)gov (Robert Goodwin)
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Dynamic SQL in function
Date: 2002-03-13 03:07:07
Message-ID: m36641upwk.fsf@varsoon.denali.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

robert(dot)goodwin(at)ums(dot)msfc(dot)nasa(dot)gov (Robert Goodwin) writes:

> I'm trying to define a simple function that uses dynamic SQL. Here is
> the function definition:
>
> CREATE OR REPLACE FUNCTION count_records (VARCHAR)
> RETURN INTEGER AS '
> DECLARE
> cursor1 REFCURSOR;
> num_recs INTEGER;
> BEGIN
> OPEN cursor1 FOR EXECUTE "SELECT count(*) FROM " ||

Don't use double quotes. Use doubled single quotes:

OPEN cursor1 FOR EXECUTE ''SELECT count(*) FROM '' || ...

Double quotes always delimit an identifier.

-Doug
--
Doug McNaught Wireboard Industries http://www.wireboard.com/

Custom software development, systems and network consulting.
Java PostgreSQL Enhydra Python Zope Perl Apache Linux BSD...

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bob T 2002-03-13 04:26:46 dxf file format
Previous Message Miguel Omar Carvajal 2002-03-13 02:38:11 Duplicate key