# How to filter insert statement and load hostname in same time by pt-query-digest

**URL:** <https://forums.percona.com/t/how-to-filter-insert-statement-and-load-hostname-in-same-time-by-pt-query-digest/5652>\
**Category:** Percona Toolkit\
**Created:** [June 1, 2017, 6:20am UTC](https://forums.percona.com/t/how-to-filter-insert-statement-and-load-hostname-in-same-time-by-pt-query-digest/5652 "2017-06-01T06:20:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dillon\_lu](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@Dillon\_lu](https://forums.percona.com/u/Dillon_lu)\
**Post date:** [June 1, 2017, 6:20am UTC](https://forums.percona.com/t/how-to-filter-insert-statement-and-load-hostname-in-same-time-by-pt-query-digest/5652/1 "2017-06-01T06:20:37Z")

</div>

Hi all,

When I load slow log to database, I have to filter some insert statements. So, my command looks like:  
pt-query-digest --filter ‘$event-\>{arg} !~ m/INSERT/i && ($event-\>{arg} !~ m/hisd/i || $event-\>{arg} !~ m/hisf/i)’ --user=app --password=xxxxxx --no-report --history h=localhost,D=percona\_db,t=query\_history\_test ./slow.log-20161226  
The above works in my case.

However, when I follow percona’s blog to add four columns, user\_max, host\_max, db\_max and hostname\_max. I failed to laod hostname to database. This is the URL of the blog: [url][https://www.percona.com/blog/2012/08/28/hidden-columns-of-query\_review\_history/[/url]](https://www.percona.com/blog/2012/08/28/hidden-columns-of-query_review_history/%5B/url%5D)

To populcate hostname, I have to use filter like this: --filter " $event-\>{Bytes} = length($event-\>{arg}) and $event-\>{hostname}=“$HOSTNAME”" But, if I merge hostname condition to my filter, I can’t get the hostname. Sometimes, the hostname\_max filed in database is blank or the pt-query-digest can’t recognize the filter condition.

Could you please give me some advise how to put hostname to database in my case? Thanks.

---

<div class="post-metadata">

**Author:** ![carlos.salguero](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/carlos.salguero/32/20_2.png) [@carlos.salguero](https://forums.percona.com/u/carlos.salguero)\
**Post date:** [June 1, 2017, 12:22pm UTC](https://forums.percona.com/t/how-to-filter-insert-statement-and-load-hostname-in-same-time-by-pt-query-digest/5652/2 "2017-06-01T12:22:41Z")

</div>

Please try escaping the quotes around $HOSTNAME to “$HOSTNAME” and also consider that string comparison operator in Perl is eq, not =  
$event-\>{hostname} eq “$HOSTNAME”

---

<div class="post-metadata">

**Author:** ![Dillon\_lu](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@Dillon\_lu](https://forums.percona.com/u/Dillon_lu)\
**Post date:** [June 2, 2017, 4:25am UTC](https://forums.percona.com/t/how-to-filter-insert-statement-and-load-hostname-in-same-time-by-pt-query-digest/5652/3 "2017-06-02T04:25:53Z")

</div>

Hi carlos,

Thanks. I did some changes one by one.  
If I use the following command:

```auto

pt-query-digest --filter '$event->{arg} !~ m/INSERT/i && ($event->{arg} !~ m/hisd/i || $event->{arg} !~ m/hisf/i) && \$event->{Bytes} = length(\$event->{arg}) and \$event->{hostname}=\"$HOSTNAME\"' --user=app --password=xxx --no-report --history h=localhost,D=percona_db,t=query_history_test slow.log-20161121

```

The error is :

```auto

Error compiling --filter code: sub { my ( $args ) = &#64;_; my $event = $args->{event}; ( $event->{arg} !~ m/INSERT/i && ($event->{arg} !~ m/hisd/i || $event->{arg} !~ m/hisf/i) && \$event->{Bytes} = length(\$event->{arg}) and \$event->{hostname}=\"$HOSTNAME\" ) && return $args; };
Can't find string terminator '"' anywhere before EOF at (eval 33) line 1.

```

It looked the filter condition was processed incorrectly.
