Re: [HACKERS] Logical decoding on standby - Mailing list pgsql-hackers

From Andrew Dunstan
Subject Re: [HACKERS] Logical decoding on standby
Date
Msg-id e3ce4edb-2521-3542-2596-c58034974bad@dunslane.net
Whole thread Raw
In response to Re: [HACKERS] Logical decoding on standby  (Craig Ringer <craig@2ndquadrant.com>)
List pgsql-hackers

On 12/22/2016 01:21 AM, Craig Ringer wrote:
>> +   my @fields = ('plugin', 'slot_type', 'datoid', 'database',
>> 'active', 'active_pid', 'xmin', 'catalog_xmin', 'restart_lsn');
>> +   my $result = $self->safe_psql('postgres', 'SELECT ' . join(', ',
>> @fields) . " FROM pg_catalog.pg_replication_slots WHERE slot_name =
>> '$slot_name'");
>> +   $result = undef if $result eq '';
>> +   # hash slice, see http://stackoverflow.com/a/16755894/398670 .
>> Couldn't this portion be made more generic? Other queries could
>> benefit from that by having a routine that accepts as argument an
>> array of column names for example.
> Yeah, probably. I'm not sure where it should live though - TestLib.pm ?
>
> Not sure if there's an idomatic way to  pass a string (in this case
> queyr) in Perl with a placeholder for interpolation of values (in this
> case columns). in Python you'd pass it with pre-defined
> %(placeholders)s for %.
>
>



For direct interpolation of an expression, there is this slightly 
baroque gadget:
   my $str = "here it is @{[ arbitrary expression here ]}";

For indirect interpolation using placeholders, there is
   my $str = sprintf("format string",...);

which works much like C except that the string is returned as a result 
instead of being the first argument.

And as we always say, TIMTOWTDI.


cheers

andrew (japh)



pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: [HACKERS] Declarative partitioning vs. sql_inheritance
Next
From: Andrew Dunstan
Date:
Subject: Re: [HACKERS] pgstattuple documentation clarification