Re: Quotes in dynamic sql - Mailing list pgsql-general

From John Sidney-Woollett
Subject Re: Quotes in dynamic sql
Date
Msg-id 4781.192.168.0.64.1072814195.squirrel@mercury.wardbrook.com
Whole thread Raw
In response to Quotes in dynamic sql  (A E <cooljoint@yahoo.com>)
Responses Re: Quotes in dynamic sql  (A E <cooljoint@yahoo.com>)
List pgsql-general
Shouldn't it be:

qry := 'SELECT * from '|| trim(realname) ||' where crmid like ''%'||
trim(crmid) ||'%''';

The contents of qry should be:

'SELECT * from blahblah where crmid like '%crmid%'

Your errors (I think) are here:


qry := ''SELECT * from ''|| trim(realname) ||'' where crmid like %''||
        ^1             ^1                    ^1                  ^2

trim(crmid) ||''%'';
               ^1  ^3

^1 = only need a single quote
^2 = the quotes are after the % when they should be before
^3 = you have a missing closing single quote

Of course, if the above is in a pl/sql procedure, then you'll need to
double up all the quotes (I think).

Hope that helps.

John Sidney-Woollett

A E said:
> Hi,
>
> I am trying to execute dynamic sql but I can't seem to get the qoutes
> right.
>
> My code is
>
> qry := ''SELECT * from ''|| trim(realname) ||'' where crmid like %''||
> trim(crmid) ||''%'';
>
> Can anyone help?
>
> Alex
>


pgsql-general by date:

Previous
From: Russ Schneider
Date:
Subject: 7.3 dump into 7.2 (my solution)
Next
From: A E
Date:
Subject: Re: Quotes in dynamic sql