That's pretty roundabout. We already expose (hex coded) pid.starttime as a session identifier in log_line_prefix (it's the %c escape) so I don't see any reason not to provide either the same thing directly in a function, or at least to expose the backend pid.
That would be nice. ---------------------------(end of broadcast)--------------------------- TIP 6: explain analyze is your friend