Plperlu function & backticks return value -> truncated?

Plperlu function & backticks return value -> truncated?

am 13.10.2004 17:07:05 von philippe.lang

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 =3D `ps -afux | grep postgres`;
@fields =3D 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 =3D `ps -afux | grep postgres`;
@fields =3D 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 =3D ps();

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

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

END LOOP;

RETURN;
END
'
LANGUAGE 'plpgsql' VOLATILE;

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


---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Re: Plperlu function & backticks return value -> truncated?

am 13.10.2004 17:25:23 von dev

Philippe Lang wrote:
> 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?

Depends if user_type is just a typo...

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

> CREATE FUNCTION public.show_users()
> RETURNS SETOF user_type AS

> user_rec line_type%ROWTYPE;

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Re: Plperlu function & backticks return value -> truncated?

am 13.10.2004 17:47:13 von Mike

On Wed, Oct 13, 2004 at 05:07:05PM +0200, Philippe Lang wrote:

> 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.

Many versions of ps truncate lines at a certain length if they can't
determine the terminal size. Since you're running ps from inside
the backend, there's probably no terminal to check. Check the ps
manual page to see if it supports an option like -w (or multiple
occurrences of -w) to increase the line length.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Re: Plperlu function & backticks return value -> truncated?

am 13.10.2004 17:54:31 von philippe.lang

Thanks! That's perfect... `ps -awfux | grep postgres` runs fine...

-----Message d'origine-----
De : Michael Fuhr [mailto:mike@fuhr.org]=20
Envoy=E9 : mercredi, 13. octobre 2004 17:47
=C0 : Philippe Lang
Cc : pgsql-sql@postgresql.org
Objet : Re: [SQL] Plperlu function & backticks return value -> truncated?

On Wed, Oct 13, 2004 at 05:07:05PM +0200, Philippe Lang wrote:

> When run directly from a shell, this code:
>=20
> $ps =3D `ps -afux | grep postgres`;
> @fields =3D split /\n/, $ps;
> return "{" . join(",", @fields) . "}";
>=20
> ... runs fine.
>=20
> But when run inside a plperlu function, lines are being truncated=20
> after a certain width.

Many versions of ps truncate lines at a certain length if they can't determ=
ine the terminal size. Since you're running ps from inside the backend, th=
ere's probably no terminal to check. Check the ps manual page to see if it=
supports an option like -w (or multiple occurrences of -w) to increase the=
line length.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster