0

系统:Windows XP Professional Postgresql 8.4 在本地存储的数据库上运行(端口 5432)

我正在使用以下代码将大小合适的文件导入数据库中的表中:

-- Create headers and column variable types
CREATE TABLE special_raw_emissions
(
ORG_ID  int     ,
COUNTY  text    ,
MID_UP_STREAM   text    ,
SITE_ID int ,
PRF_ID  int ,
RN  text    ,
ACCOUNT text    ,
CERTIFYING_COMPANY_ORGANIZATION text    ,
LEASE_NAME  text    ,
LEASE_NUMBER    text    ,
SOURCE  text    ,
FACILITY_ID int ,
PROFILE text    ,
LATITUDE    float   ,
LONGITUDE   float   ,
OIL_bbl_yr  float   ,
CASINGHEAD_GAS_scf_yr   float   ,
GAS_WELL_GAS_scf_yr float   ,
CONDENSATE_bbl_yr   float   ,
PRODUCED_WATER_bbl_yr   float   ,
TOTAL_VOC_EMISSION_tpy_EXTRACTED_FROM_SE_TAB    float   ,
CONTROL_PRESENT boolean ,
CONTROL_TYPE    text    ,
CONTROL_TYPE_IF_OTHER_DESCRIBE  text    ,
NOX_CONTROL_EFFICIENCY_PCNT float   ,
VOC_CONTROL_EFFICIENCY_PCNT float   ,
VENTED_VOLUME_scf_yr    float   ,
BLOWDOWN_EVENTS int ,
OPERATING_HOURS_hrs_yr  float   ,
FUEL_CONSUMPTION_MMscf_yr   float   ,
PILOT_GAS_USED_MMscf_yr float   ,
WASTE_GAS_COMBUSTED_MMscf_yr    float   ,
GAS_TREATED_MMscf_yr    float   ,
AVERAGE_DAILY_PRODUCTION_RATE_MMscf_day float   ,
THROUGHPUT_bbl_yr   float   ,
SEPARATOR_PRESSURE_psig float   ,
SEPARATOR_TEMPERATURE_deg_F float   ,
GAS_GRAVITY float   ,
MAXIMUM_DAILY_PRODUCTION_bbl_day    text    ,
SOURCE_ANNUAL_THROUGHPUT_bbl_yr float   ,
ANNUAL_THROUGHPUT_bbl_yr    float   ,
MAXIMUM_DAILY_PRODUCTION_RATE__bbl_day  float   ,
SERIAL_NUMBER   text    ,
MAKE    text    ,
MODEL   text    ,
FUEL_TYPE   text    ,
MAXIMUM_DESIGN_CAPACITY text    ,
BURN_TYPE   text    ,
CYCLE   text    ,
ENGINE_RATING   text    ,
ASSIST_TYPE text    ,
AUTOMATIC_AIR_TO_FUEL_RATIO_CONTROLLER  boolean ,
DESTRUCTION_EFFICIENCY  text    ,
SUBJECT_TO_MACT boolean ,
IF_YES_INDICATE_MAJOR_OR_AREA_SOURCE    text    ,
SOURCE_TYPE text    ,
IF_CONDENSER_WHAT_IS_EFFICIENCY text    ,
LIQUID_TYPE text    ,
IS_HARC_51C_ACCEPTED_METHOD text    ,
WOULD_YOU_LIKE_TO_USE_HARC  text    ,
SINGLE_OR_MULTIPLE_TANKS    text    ,
NUMBER_OF_TANKS int ,
CONFIGURATION_TYPE  text    ,
WORKING_AND_BREATHING_EMISS_CALC_METHOD text    ,
FLASH_EMISS_CAL_METHOD  text    ,
FLASH_IF_OTHER_PLEASE_DESCRIBE  text    ,
IS_MONITORING_PROGRAM_VOLUNTARY int ,
AIR_ACTUATED_PNEUMATIC_VALVES_GAS   int ,
AIR_ACTUATED_PNEUMATIC_VALVES_LIGHT_OIL int ,
CONNECTORS_GAS  int ,
CONNECTORS_LIGHT_OIL    int ,
FLANGES_GAS int ,
FLANGES_LIGHT_OIL   int ,
GAS_ACTUATED_PNEUMATIC_VALVES_GAS   int ,
GAS_ACTUATED_PNEUMATIC_VALVES_LIGHT_OIL int ,
IS_COMPLETION_OPTIONAL  text    ,
NONACTUATED_VALVES_GAS  int ,
NONACTUATED_VALVES_LIGHT_OIL    int ,
OPEN_ENDED_LINES_GAS    int ,
OPEN_ENDED_LINES_LIGHT_OIL  int ,
OTHER_GAS   int ,
OTHER_LIGHT_OIL int ,
PUMP_SEALS_GAS  int ,
PUMP_SEALS_LIGHT_OIL    int ,
TOTAL_COMPONENTS    int ,
TOTAL_PUMPS_AND_COMPRESSOR_SEALS    text    ,
TOTAL_UNCONTROLLED_RELIEF_VALVES    text    ,
GAS_ACTUATED_PNEUMATIC_VALVES_HEAVY_OIL int ,
AIR_ACTUATED_PNEUMATIC_VALVES_HEAVY_OIL int ,
NON_ACTUATED_VALVES_HEAVY_OIL   int ,
PUMP_SEALS_HEAVY_OIL    int ,
CONNECTORS_HEAVY_OIL    int ,
FLANGES_HEAVY_OIL   int ,
OPEN_ENDED_LINES_HEAVY_OIL  int ,
OTHER_HEAVY_OIL int ,
GAS_ACTUATED_PNEUMATIC_VALVES_WATER_SLASH_OIL   text    ,
AIR_ACTUATED_PNEUMATIC_VALVES_WATER_SLASH_OIL   int ,
NON_ACTUATED_VALVES_WATER_SLASH_OIL int ,
PUMP_SEALS_WATER_SLASH_OIL  int ,
CONNECTORS_WATER_SLASH_OIL  int ,
FLANGES_WATER_SLASH_OIL int ,
OPEN_ENDED_LINES_WATER_SLASH_OIL    int ,
OTHER_WATER_SLASH_OIL   text    ,
VOC_Gas_Mole_Percent    float   ,
BENZENE_Gas_Mole_Percent    float   ,
ETHYBENZENE_Gas_Mole_Percent    float   ,
n_HEXANE_Gas_Mole_Percent   float   ,
TOLUENE_Gas_Mole_Percent    float   ,
XYLENE_S_Gas_Mole_Percent   float   ,
HAPs_Gas_Mole_Percent   float   ,
VOC_Liquid_Mole_Percent float   ,
BENZENE_Liquid_Mole_Percent float   ,
ETHYBENZENE_Liquid_Mole_Percent float   ,
n_HEXANE_Liquid_Mole_Percent    float   ,
TOLUENE_Liquid_Mole_Percent float   ,
XYLENE_S_Liquid_Mole_Percent    float   ,
HAPs_Liquid_Mole_Percent    float   ,
VOC_Control_Factor_PERC float   ,
CH4_Emission_Factor_tonne_Btu   float,
Engine_LF   float   ,
CO2_M1  float   ,
CO2_M2  float   ,
CH4_M1  float   ,
CH4_M2  float   ,
Source_Class    text    ,
Site_class  text);

-- Import data into database, note that the delimiter is '~'.
COPY special_raw_emissions
FROM 'C:/PostgreSQL/special results/batch.csv'
WITH DELIMITER AS '~' 
CSV;

我遇到了一些奇怪的错误,所以我做了一个QA检查并查询了这个表,看看数据是否正确导入,如下所示是查询:

\o 'c:/postgresql/special_raw_emissions.csv'
select * from special_raw_emissions;
\o

我的查询返回所有导入的数据,但随机添加了“空行”。下面显示的是“空行”的示例。

数据输入:

155 Wise    Midstream   8250    1
155 Wise    Midstream   8250    1
4   Wise    Upstream    7220    1
4   Wise    Upstream    7220    1
95  Wise    Midstream   7742    1
95  Wise    Midstream   7742    1
7   Clay    Upstream    1990    7
7   Cooke   Upstream    1414    7

具有空行的数据(下面显示的示例建议了一种模式,在较大的输出文件中不是这种情况)

7   Clay    Upstream    1990    7
7   Cooke   Upstream    1414    7

7   Cooke   Upstream    1415    7
7   Cooke   Upstream    1416    7

7   Cooke   Upstream    3355    7
7   Cooke   Upstream    3356    7

7   Cooke   Upstream    1418    7
7   Cooke   Upstream    3357    7

7   Cooke   Upstream    1419    7
7   Cooke   Upstream    7489    7

就像我之前所说的,这些空行导致我的查询丢失某些数据并且我正在丢失信息。

非常感谢任何帮助或指导!

4

1 回答 1

0

问题分两步解决。

  1. 在 excel 中打开原始数据,使用适当的分隔符(在我的情况下为“~”)保存数据并关闭文件。

  2. 将数据重新导入数据库。

我的猜测是,使用另一个 psql 查询创建的原始数据以某种方式损坏或缺少行结束字符。在 excel 中重新保存修复了该问题并允许导入正常工作。

我仍然觉得好像问题没有解决,我只是找到了一个解决方法。

于 2012-05-12T02:19:04.397 回答