Can anyone explain why the first one never completes, but the second one does? 
(the first one just keeps running, I canceled after ~1 min)
PG version: 8.1 final

-- tblname param has type varchar
create or replace function getcolstring (tblname varchar) returns varchar as $$
declare
     table_columns varchar := '';
     column_name record;
begin
     for column_name in select pga.attname from pg_attribute pga, pg_class pgc
         where pga.attrelid = pgc.relfilenode and pgc.relname = tblname and 
pga.attnum > 0 loop
         table_columns := table_columns || column_name.attname || ',';
     end loop;

     -- chop the last ','
     table_columns := substr(table_columns,1,(length(table_columns)-1));
     
     return table_columns;
     
end;
$$
language plpgsql;


-- tblname param has type text
create or replace function getcolstring (tblname text) returns varchar as $$
declare
     table_columns varchar := '';
     column_name record;
begin
     for column_name in select pga.attname from pg_attribute pga, pg_class pgc
         where pga.attrelid = pgc.relfilenode and pgc.relname = tblname and 
pga.attnum > 0 loop
         table_columns := table_columns || column_name.attname || ',';
     end loop;

     -- chop the last ','
     table_columns := substr(table_columns,1,(length(table_columns)-1));
     
     return table_columns;
     
end;
$$
language plpgsql;


/Mikael

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

Reply via email to