in reply to perl and psql

<bold>update</bold> I didn't read your code too well, so disregard the below.

Perl is nice, but you don't always need it: there is also the direct SQL possibility (syntax: create table new_table as myquery):

-- drop table if exists new_table; create table new_table as ( select sequence_start,sequence_stop from intergenic_and_experimental_results where reading_direction = 'f' ) union all ( select sequence_start,sequence_stop from intergenic_and_experimental_results where reading_direction = 'r' ) order by reading_direction, sequence_start ;

I always run a manual analyze on newly created table, just to make sure statistics (on which the planner relies) are up to date: 'analyze mytable;'

postgres manual: CREATE TABLE AS

(Or, in case you want to insert into an existing table: INSERT INTO (syntax: insert into mytable myquery)

(Or, in case you want to create a tab-separated file: COPY TO (syntax: copy ( myquery ) to 'file.txt' csv delimiter E'\t')

(and just btw: postgres is designated 'pgsql'; psql being the cli client)