[postgis-users] Using string variables with PGScript

Birgit Laggner birgit.laggner at ti.bund.de
Thu Sep 24 06:22:42 PDT 2015


Hi Bob,

I would recommend something as simple as

SELECT * from mytable where myfield = '@MYSTRING';

I tried using a string variable in a PGScript once, too, and if I 
remember correctly, quote_literal() did not work.

Good luck and regards,

Birgit




Am 24.09.2015 um 03:43 schrieb David Fawcett:
> Bob,
>
> I haven't ever used PGScript, but I wonder one of the postgres quote 
> functions found on this page might work: 
> http://www.postgresql.org/docs/9.1/static/functions-string.html
>
> I would try quote_literal()
>
> David.
>
> On Wed, Sep 23, 2015 at 4:26 PM, Bistrais, Bob <Bob.Bistrais at maine.gov 
> <mailto:Bob.Bistrais at maine.gov>> wrote:
>
>     I am having trouble using a variable in a Select statement, using
>     PGScript.  I am trying to define a string variable, then use it in
>     the Select statement.  Something like this:
>
>     DECLARE @MYSTRING;
>
>     SET @MYSTRING = CAST(@REC[0]['mycode'] AS STRING);   -- at REC was
>     set from a previous select
>
>     SELECT * from mytable where myfield = @MYSTRING;
>
>     -The variable is not quoted, so the select statement fails.  How
>     do I get the string variable to be enclosed in quotes?
>
>
>     _______________________________________________
>     postgis-users mailing list
>     postgis-users at lists.osgeo.org <mailto:postgis-users at lists.osgeo.org>
>     http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users
>
>
>
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at lists.osgeo.org
> http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20150924/8ed2df10/attachment.html>


More information about the postgis-users mailing list