[Pgsql-ayuda] Cual es el error
Alvaro Herrera
alvherre@dcc.uchile.cl
Tue, 2 Sep 2003 22:59:08 -0400
On Tue, Sep 02, 2003 at 10:57:28PM +0000, Edwin Quijada wrote:
> No le gusto tampoco!! Tiro la toalla!!! :(
Ok, esto funciona:
alvherre=> CREATE OR REPLACE FUNCTION cortar_char(name, name, varchar) RETURNS int4 AS '
DECLARE
tabla ALIAS FOR $1;
campo ALIAS FOR $2;
dato ALIAS FOR $3;
len int;
reg record;
BEGIN
select into reg b.atttypmod - 4 as lon
from pg_class a, pg_attribute b, pg_type c
where a.relname = tabla
and b.attrelid = a.relfilenode
and b.attname = campo
and b.attnum >0
and b.atttypid = c.oid;
len:=reg.lon;
return len;
END;'
LANGUAGE 'plpgsql';
CREATE
alvherre=> create table foo (uno varchar(20));
CREATE
alvherre=> select cortar_char('foo'::name, 'uno'::name, 'uno dos tres cuatro cinco seis siete'::varchar);
cortar_char
-------------
20
(1 registro)
--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"A wizard is never late, Frodo Baggins, nor is he early.
He arrives precisely when he means to." (Gandalf, en LoTR FoTR)