pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedPlperlu function & backticks return value -> truncated?
5+ messages / 3 participants
[nested] [flat]
* Plperlu function & backticks return value -> truncated?
@ 2004-10-13 15:07 Philippe Lang <philippe.lang@attiksystem.ch>
0 siblings, 2 replies; 5+ messages in thread
From: Philippe Lang @ 2004-10-13 15:07 UTC (permalink / raw)
To: 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();
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Plperlu function & backticks return value -> truncated?
@ 2004-10-13 15:25 Richard Huxton <dev@archonet.com>
parent: Philippe Lang <philippe.lang@attiksystem.ch>
1 sibling, 0 replies; 5+ messages in thread
From: Richard Huxton @ 2004-10-13 15:25 UTC (permalink / raw)
To: Philippe Lang <philippe.lang@attiksystem.ch>; +Cc: pgsql-sql
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
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Plperlu function & backticks return value -> truncated?
@ 2004-10-13 15:42 Philippe Lang <philippe.lang@attiksystem.ch>
0 siblings, 0 replies; 5+ messages in thread
From: Philippe Lang @ 2004-10-13 15:42 UTC (permalink / raw)
To: pgsql-sql
Hello,
Yes, I made a typo, sorry. I've been playing with different types this afternoon, that's why.
But "user_type" was also made up of a "text" field, just like "line_type", so the problem is still here...
-----Message d'origine-----
De : Richard Huxton [mailto:dev@archonet.com]
Envoyé : mercredi, 13. octobre 2004 17:25
À : Philippe Lang
Cc : pgsql-sql@postgresql.org
Objet : Re: [SQL] Plperlu function & backticks return value -> truncated?
> Is that a known limitation of plperlu? Or maybe something else?
Depends if user_type is just a typo...
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Plperlu function & backticks return value -> truncated?
@ 2004-10-13 15:47 Michael Fuhr <mike@fuhr.org>
parent: Philippe Lang <philippe.lang@attiksystem.ch>
1 sibling, 0 replies; 5+ messages in thread
From: Michael Fuhr @ 2004-10-13 15:47 UTC (permalink / raw)
To: Philippe Lang <philippe.lang@attiksystem.ch>; +Cc: pgsql-sql
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/
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Plperlu function & backticks return value -> truncated?
@ 2004-10-13 15:54 Philippe Lang <philippe.lang@attiksystem.ch>
0 siblings, 0 replies; 5+ messages in thread
From: Philippe Lang @ 2004-10-13 15:54 UTC (permalink / raw)
To: Michael Fuhr <mike@fuhr.org>; +Cc: pgsql-sql
Thanks! That's perfect... `ps -awfux | grep postgres` runs fine...
-----Message d'origine-----
De : Michael Fuhr [mailto:mike@fuhr.org]
Envoyé : mercredi, 13. octobre 2004 17:47
À : 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:
>
> $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/
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2004-10-13 15:54 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-10-13 15:07 Plperlu function & backticks return value -> truncated? Philippe Lang <philippe.lang@attiksystem.ch>
2004-10-13 15:25 ` Richard Huxton <dev@archonet.com>
2004-10-13 15:47 ` Michael Fuhr <mike@fuhr.org>
2004-10-13 15:42 Re: Plperlu function & backticks return value -> truncated? Philippe Lang <philippe.lang@attiksystem.ch>
2004-10-13 15:54 Re: Plperlu function & backticks return value -> truncated? Philippe Lang <philippe.lang@attiksystem.ch>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox