非空字段中具有类似null值的空行

时间:2010-08-29 23:20:45

标签: postgresql

我正在使用postgresql 9.0 beta 4.

将大量数据插入分区表后,我发现了一个奇怪的事情。当我查询表时,我可以在'not-null'字段中看到一个空类值为空的行。

奇怪的查询结果如下所示。

alt text

第689行是空的。前3个字段(stid,d,ticker)正在构成主键。所以他们不应该是空的。我使用的查询就是这个。

select * from st_daily2 where stid=267408 order by d

我甚至可以根据这些数据进行分组。

select stid, date_trunc('month', d) ym, count(*) from st_daily2 
where stid=267408 group by stid, date_trunc('month', d)

'group by'结果仍然是空行。

alt text

第一行是空的。 但是,如果我查询'stid'或'd'为null,那么它什么也不返回。

这是postgresql 9b4的错误吗?或者一些数据损坏?

编辑:

  1. 我添加了我的表定义。

    CREATE TABLE st_daily
    (
    stid integer NOT NULL,
    d date NOT NULL,
    ticker character varying(15) NOT NULL,
    mp integer NOT NULL,
    settlep double precision NOT NULL,
    prft integer NOT NULL,
    atr20 double precision NOT NULL,
    upd timestamp with time zone,
    ntrds double precision
    )
    WITH (
    OIDS=FALSE
    );
    
    
    CREATE TABLE st_daily2
    (
    CONSTRAINT st_daily2_pk PRIMARY KEY (stid, d, ticker),
    CONSTRAINT st_daily2_strgs_fk FOREIGN KEY (stid)
        REFERENCES strgs (stid) MATCH SIMPLE
        ON UPDATE CASCADE ON DELETE CASCADE,
    CONSTRAINT st_daily2_ck CHECK (stid >= 200000 AND stid < 300000)
    )
    INHERITS (st_daily)
    WITH (
    OIDS=FALSE
    );
    
  2. 此表中的数据是模拟结果。用c#编写的多线程多模拟引擎使用Npgsql将数据插入数据库。

  3. psql也会显示空行。

  4. alt text

3 个答案:

答案 0 :(得分:1)

您最好在http://www.postgresql.org/support/submitbug

留言

有些问题:

  1. 你能表现出来吗? 的定义和约束 partions?
  2. 您是如何加载数据的?
  3. 使用时会得到相同的结果 另一个工具,如psql

答案 1 :(得分:1)

你的问题的答案很可能在于你的第一句话:

  

我正在使用postgresql 9.0 beta 4。

你为什么这样做?升级到稳定版本。 Preferably the latest point-release of the current version. 截至今天,这是 9.1.4

答案 2 :(得分:0)

我得到了同样的观点:“那个空白值是什么?” 不,它不是NULL,而是-infinity

要过滤这样的行使用:

WHERE 
  case when mytestcolumn = '-infinity'::timestamp or
            mytestcolumn = 'infinity'::timestamp 
  then NULL else mytestcolumn end IS NULL

而不是:

WHERE mytestcolumn IS NULL