copyfields(p_tab_id integer)

8.40. copyfields(p_tab_id integer)

Function Properties

Language: PLPGSQL

Return Type: text

Return a string consisting of what should be appended to a COPY statement to specify fields for the passed-in tab_id. In PG versions > 7.3, this looks like (field1,field2,...fieldn)

	result text;
	prefix text;
	prec record;
	result := '';
	prefix := '(';   -- Initially, prefix is the opening paren

	for prec in select slon_quote_input(a.attname) as column from sl_table t, pg_catalog.pg_attribute a where t.tab_id = p_tab_id and t.tab_reloid = a.attrelid and a.attnum > 0 and a.attisdropped = false order by attnum
		result := result || prefix || prec.column;
		prefix := ',';   -- Subsequently, prepend columns with commas
	end loop;
	result := result || ')';
	return result;