Re: how to store a query, that results in a table - Mailing list pgsql-sql

From Jie Liang
Subject Re: how to store a query, that results in a table
Date
Msg-id 39CBD205.9A922DDE@ipinc.com
Whole thread Raw
In response to how to store a query, that results in a table  (root <nbrito@cmet.net>)
List pgsql-sql
Hi, there, <p>If the client machine is a trusted machine in your company, use remote shell 'rsh' can <br />call a
scriptof SQL. <br />If not , you had better use embeded SQL. <p>I don't know how visual basic embed SQL, but I think is
sameway as other language, <br />in postgres: <br />#db> create  user robot with password 'wowwow'; <br />$db>
grantall on table1 to robot; <p>In perl , it's very similar like this: <br />use Pg; <br />my $conn; <br />        sub
connectDb{ <br />           $conn = Pg::connectdb("dbname=db host=dbserver port=5432 user=robot password=wowwow"); <br
/>          if ( $conn->status != Pg::PGRES_CONNECTION_OK ) { <br />                die "Cant open postgres! : " .
$conn->errorMessage. "\n"; <br />                } <br />           return; <br />         } <br />#main <br
/>       connectDb(); <br />        my $query="select * from table1 where row1=parameter1"; <br />        print
$query,"\n";<br />        my $res=$conn->exec($query); <br />        $res->cmdStatus || die
$conn->errorMessage.":$!\n";<br />        my $rows= $res->ntuples; <br />        for (my $k = 0 ; $k < $rows;
$k++){<br />                my $field1=$res->getvalue($k,0); <br />                my
$field2=$res->getvalue($k,1);<br />                print $field1,"\t",field2,"\n"; <br />        } <br />  <p>root
wrote:<blockquote type="CITE">hi. <br />I have a problem. <br />I require to store a query sql in postgresql-7.0 like:
<br/>example. <br />select * from table1 where row1(table1)=parameter1 <br />If i execute this query directly, I don't
haveproblem. <br />I want to store this query in order to execute from a client program <br />(visual basic 6.0), but i
don'tknow how to? <br />I tried to store the query like a function (create function ...), but it <br />was impossible
tofind a way in order to obtain a table like result. <br />Only we could obtain a single row by using the rtype "
returnssetof <br />varchar". <br />I hope a soon answer. <br />Thank you. <br /> Nelson B.</blockquote><pre>-- 
 
Jie LIANG

Internet Products Inc.

10350 Science Center Drive
Suite 100, San Diego, CA 92121
Office:(858)320-4873

jliang@ipinc.com
www.ipinc.com</pre>  

pgsql-sql by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: sql query not using indexes
Next
From: Nelson
Date:
Subject: how to store a query, that results in a table