Skip site navigation (1) Skip section navigation (2)

Plperlu function & backticks return value -> truncated?

From: "Philippe Lang" <philippe(dot)lang(at)attiksystem(dot)ch>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Plperlu function & backticks return value -> truncated?
Date: 2004-10-13 15:07:05
Message-ID: 6C0CF58A187DA5479245E0830AF84F42142C54@poweredge.attiksystem.ch (view raw or flat)
Thread:
Lists: pgsql-sql
Hello,

I'm using the following show_users() function in order to retreive in
postgresql the output from the unix "ps" command.

When run directly from a shell, this code:

  $ps = `ps -afux | grep postgres`;
  @fields = split /\n/, $ps;
  return "{" . join(",", @fields) . "}";

... runs fine.

But when run inside a plperlu function, lines are being truncated after
a certain width.

Is that a known limitation of plperlu? Or maybe something else?



Philippe

------------------------------------------------------------
--  TYPE: line_type
------------------------------------------------------------
CREATE TYPE public.line_type AS
(
  line text
);

------------------------------------------------------------
--  UTILITY FUNCTION: ps
------------------------------------------------------------
CREATE FUNCTION public.ps()
  RETURNS text[] AS
'
  $ps = `ps -afux | grep postgres`;
  @fields = split /\n/, $ps;
  return "{" . join(",", @fields) . "}";
'
  LANGUAGE 'plperlu' VOLATILE;

------------------------------------------------------------
--  UTILITY FUNCTION: show_users
------------------------------------------------------------
CREATE FUNCTION public.show_users()
  RETURNS SETOF user_type AS
'
DECLARE
  users        text[];
  user_rec     line_type%ROWTYPE;
  i            int2;

BEGIN
  users = ps();

  FOR i IN 1 .. array_upper(users, 1) LOOP

    user_rec.line = users[i];
    RETURN NEXT user_rec;

  END LOOP;

  RETURN;
END
'
  LANGUAGE 'plpgsql' VOLATILE;

------------------------------------------------------------
--  MAIN
------------------------------------------------------------
select * from show_users();


Responses

pgsql-sql by date

Next:From: Richard HuxtonDate: 2004-10-13 15:25:23
Subject: Re: Plperlu function & backticks return value -> truncated?
Previous:From: LoriDate: 2004-10-13 00:20:28
Subject: help with to_date and to_char

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group