David:
On Wed, Jun 6, 2018 at 5:36 PM, David Gauthier <davegauthierpg@gmail.com> wrote:
> Hi:
>
> Is there a way to do the equivalent of a "\set foo 1" through perl dbi ?
> I tried...
> $dbh->do("\\set foo 1");
> and got a syntax error
>
> Of course, I'd also have to be able to access the value of foo once its set.
> I'm guessing the usual way ??? (select :foo)
You are looking at it wrong. Psql vars are similar to perl vars, and
it is psql ( the program in your machine ) who interpolates them
before sending the query to the server.
The equivalent perl code to
\set foo 1
select :foo;
Would be
my $foo = '1';
$dbh->do("select $foo")
Which is not terribly useful, in perl.
To use the current ( client ) user in a query ( like your next message
states ), you just need
$dbh->do("select * from some_table where user_id_column=$<")
( Of course, you could "use English;" to get $UID, or use placeholders
to avoid injections, that's just an initial pointer )
( or "perldoc perlvar" if you do not know what $< is, and that is
enough perl stuff for a postres list )
Francisco Olarte