[prev in list] [next in list] [prev in thread] [next in thread] 

List:       postgis-users
Subject:    Re: [postgis-users] Using string variables with PGScript
From:       Birgit Laggner <birgit.laggner () ti ! bund ! de>
Date:       2015-09-24 13:22:42
Message-ID: 5603F922.4090801 () ti ! bund ! de
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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@maine.gov 
> <mailto:Bob.Bistrais@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);   --@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@lists.osgeo.org <mailto:postgis-users@lists.osgeo.org>
>     http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users
>
>
>
>
> _______________________________________________
> postgis-users mailing list
> postgis-users@lists.osgeo.org
> http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users


[Attachment #5 (text/html)]

<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Hi Bob,<br>
    <br>
    I would recommend something as simple as<br>
    <br>
    SELECT * from mytable where myfield = '@MYSTRING';<br>
    <br>
    I tried using a string variable in a PGScript once, too, and if I
    remember correctly, quote_literal() did not work.<br>
    <br>
    Good luck and regards,<br>
    <br>
    Birgit<br>
    <br>
    <br>
    <br>
    <br>
    <div class="moz-cite-prefix">Am 24.09.2015 um 03:43 schrieb David
      Fawcett:<br>
    </div>
    <blockquote
cite="mid:CAF7K3b8x=jEBPMWTa_B4hUOSNK=45tE0nM1xcjyS9wWRmoUodQ@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div>
          <div>
            <div>Bob, <br>
              <br>
            </div>
            I haven't ever used PGScript, but I wonder one of the
            postgres quote functions found on this page might work:  <a
              moz-do-not-send="true"
              href="http://www.postgresql.org/docs/9.1/static/functions-string.html">http://www.postgresql.org/docs/9.1/static/functions-string.html</a><br>
  <br>
          </div>
          I would try quote_literal()<br>
          <br>
        </div>
        David.<br>
      </div>
      <div class="gmail_extra"><br>
        <div class="gmail_quote">On Wed, Sep 23, 2015 at 4:26 PM,
          Bistrais, Bob <span dir="ltr">&lt;<a moz-do-not-send="true"
              href="mailto:Bob.Bistrais@maine.gov" \
target="_blank">Bob.Bistrais@maine.gov</a>&gt;</span>  wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div link="blue" vlink="purple" lang="EN-US">
              <div>
                <p class="MsoNormal">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:</p>
                <p class="MsoNormal"> </p>
                <p class="MsoNormal">DECLARE @MYSTRING;</p>
                <p class="MsoNormal">SET @MYSTRING =
                  CAST(@REC[0]['mycode'] AS STRING);   --@REC was set
                  from a previous select</p>
                <p class="MsoNormal"> </p>
                <p class="MsoNormal">SELECT * from mytable where myfield
                  = @MYSTRING;</p>
                <p class="MsoNormal"> </p>
                <p class="MsoNormal">-The variable is not quoted, so the
                  select statement fails.  How do I get the string
                  variable to be enclosed in quotes?</p>
                <p class="MsoNormal"> </p>
                <p class="MsoNormal"> </p>
              </div>
            </div>
            <br>
            _______________________________________________<br>
            postgis-users mailing list<br>
            <a moz-do-not-send="true"
              href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a><br>
  <a moz-do-not-send="true"
              href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users"
              rel="noreferrer" \
target="_blank">http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users</a><br> \
</blockquote>  </div>
        <br>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
postgis-users mailing list
<a class="moz-txt-link-abbreviated" \
href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a> <a \
class="moz-txt-link-freetext" \
href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users">http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users</a></pre>
  </blockquote>
    <br>
  </body>
</html>



_______________________________________________
postgis-users mailing list
postgis-users@lists.osgeo.org
http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic