To overcome the shortcoming of version 8.1 you can create a TEMPORARY TABLE
and use it in COPY TO
:
CREATE TEMP TABLE t_tmp AS
SELECT * FROM tablename LIMIT 100;
COPY t_tmp TO '/absolute/path/to/file';
Temp. tables are dropped at the end of a session automatically. If you want to keep the connection open you could drop the table explicitly or wrap it in a transaction which you roll back (what's already written to the file is never rolled back.)
BEGIN;
CREATE ...;
COPY ...;
ROLLBACK;
Or you upgrade to a more recent version, which would be a very good idea in general.
PostgreSQL 8.1 has reached end of life in Nov. 2010.