我在 Windows 7 x64 上运行 Postgres 9.1.3 32 位。(必须使用 32 位,因为没有与 64 位 Postgres 兼容的 Windows PostGIS 版本。)(编辑:从 PostGIS 2.0 开始,它与 Windows 上的 Postgres 64 位兼容。)
我有一个查询将一个表 ( consistent.master
) 与一个临时表连接起来,然后将结果数据插入到第三个表 ( consistent.masternew
) 中。
由于这是 a left join
,因此结果表应该与查询中的左表具有相同的行数。但是,如果我运行这个:
SELECT count(*)
FROM consistent.master
我明白了2085343
。但是如果我运行这个:
SELECT count(*)
FROM consistent.masternew
我明白了2085703
。
怎么能masternew
有更多的行数master
?不应该与查询中的左表masternew
具有相同的行数吗?master
下面是查询。和表应该具有相同的结构master
。masternew
--temporary table created here
--I am trying to locate where multiple tickets were written on
--a single traffic stop
WITH stops AS (
SELECT citation_id,
rank() OVER (ORDER BY offense_timestamp,
defendant_dl,
offense_street_number,
offense_street_name) AS stop
FROM consistent.master
WHERE citing_jurisdiction=1
)
--Here's the insert statement. Below you'll see it's
--pulling data from a select query
INSERT INTO consistent.masternew (arrest_id,
citation_id,
defendant_dl,
defendant_dl_state,
defendant_zip,
defendant_race,
defendant_sex,
defendant_dob,
vehicle_licenseplate,
vehicle_licenseplate_state,
vehicle_registration_expiration_date,
vehicle_year,
vehicle_make,
vehicle_model,
vehicle_color,
offense_timestamp,
offense_street_number,
offense_street_name,
offense_crossstreet_number,
offense_crossstreet_name,
offense_county,
officer_id,
offense_code,
speed_alleged,
speed_limit,
work_zone,
school_zone,
offense_location,
source,
citing_jurisdiction,
the_geom)
--Here's the select query that the insert statement is using.
SELECT stops.stop,
master.citation_id,
defendant_dl,
defendant_dl_state,
defendant_zip,
defendant_race,
defendant_sex,
defendant_dob,
vehicle_licenseplate,
vehicle_licenseplate_state,
vehicle_registration_expiration_date,
vehicle_year,
vehicle_make,
vehicle_model,
vehicle_color,
offense_timestamp,
offense_street_number,
offense_street_name,
offense_crossstreet_number,
offense_crossstreet_name,
offense_county,
officer_id,
offense_code,
speed_alleged,
speed_limit,
work_zone,
school_zone,
offense_location,
source,
citing_jurisdiction,
the_geom
FROM consistent.master LEFT JOIN stops
ON stops.citation_id = master.citation_id
万一这很重要,我已经运行了一个VACUUM FULL ANALYZE
并重新索引了两个表。(不确定确切的命令;通过 pgAdmin III 完成。)