我需要向客户端提供来自制表符分隔文件中的几个postgres表的数据。我已使用以下代码在.tsv文件中生成它。 但是他回来要求我在制表符分隔的csv文件中提供它。
除了重新命名或将其移动到.txt文件之外,您能否建议我如何做到这一点。
此致 维杰
psql -d vijay -U postgres -t -A -c "select a.key,a.name,cf.categories,cf.features,regexp_replace(a.iphone_description, E'[\\n\\r]+', ' ', 'g' ),a.sms_name,replace(a.sms_address,',',':'),a.sms_phone,a.sms_subscribe_string,a.iphone_name,replace(a.iphone_address,',',':'),a.iphone_city,a.iphone_state_key,a.iphone_zip,a.iphone_phone,a.iphone_logo_suffix,a.iphone_banner_suffix,a.iphone_url,a.start_date,a.end_date,a.disabled,a.is_deletable,a.cms_type,a.deleted,a.banner_enabled,a.latitude,a.longitude from .advertiser a LEFT OUTER JOIN (select cat.ad_key as key,fe.name,cat.categories,fe.features from .temp_cat cat FULL OUTER JOIN .temp_features fe on (cat.ad_key=fe.key))cf ON (a.key=cf.key) and a.cms_type='poi'" > poi_10072014.tsv
regexp_replace(a.iphone_description, E'[\\n\\r]+', ' ', 'g' )
COPY (select a.key,a.name,cf.categories,cf.features,regexp_replace(a.iphone_description, E'\n|\r',' ', 'g' ),a.sms_name,replace(a.sms_address,',',':'),a.sms_phone,a.sms_subscribe_string,a.iphone_name,replace(a.iphone_address,',',':'),a.iphone_city,a.iphone_state_key,a.iphone_zip,a.iphone_phone,a.iphone_logo_suffix,a.iphone_banner_suffix,a.iphone_url,a.start_date,a.end_date,a.disabled,a.is_deletable,a.cms_type,a.deleted,a.banner_enabled,a.latitude,a.longitude from advertiser a LEFT OUTER JOIN (select cat.ad_key as key,fe.name,cat.categories,fe.features from temp_cat cat FULL OUTER JOIN temp_features fe on (cat.ad_key=fe.key))cf ON (a.key=cf.key) and a.cms_type='poi') TO 'poi_11072014.txt' WITH DELIMITER E'\t';
ERROR: syntax error at or near "(" at character 6
LINE 1: COPY (select a.key,a.name,cf.categories,cf.features,regexp_r...
答案 0 :(得分:5)
您可以使用以下COPY命令:
COPY (SELECT * FROM TABLE_NAME) TO 'D:\Demo1.tsv'
编辑.txt文件:
COPY (SELECT * FROM t_offer_master) TO 'D:\Demo1.txt' WITH DELIMITER E'\t';
编辑\ n,\ r \ n替换
COPY (SELECT id,regexp_replace(name,E'\n|\r',' ','g') FROM table_name) TO 'D:\
Demo1.txt' WITH DELIMITER E'\t';