开发者

an empty row with null-like values in not-null field

I'm using postgresql 9.0 beta 4.

After inserting a lot of data into a partitioned table, i found a weird thing. When I query the table, i can see an empty row with null-like values in 'not-null' fields.

That weird query result is like below.

an empty row with null-like values in not-null field

689th row is empty. The first 3 fields, (stid, d, ticker), are composing primary key. So they should not be null. The query i used is this.

select * from st_daily2 where stid=267408 order by d

I can even do the group by on this data.

select stid, date_trunc('month', d) ym, count(*) from st_daily2 
where stid=267408 group by stid, date_trunc('m开发者_如何学Conth', d)

The 'group by' results still has the empty row.

an empty row with null-like values in not-null field

The 1st row is empty. But if i query where 'stid' or 'd' is null, then it returns nothing.

Is this a bug of postgresql 9b4? Or some data corruption?

EDIT :

  1. I added my table definition.

    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. The data in this table is simulation results. Multithreaded multiple simulation engines written in c# insert data into the database using Npgsql.

  3. psql also shows the empty row.

an empty row with null-like values in not-null field


You'd better leave a posting at http://www.postgresql.org/support/submitbug

Some questions:

  1. Could you show use the table definitions and constraints for the partions?
  2. How did you load your data?
  3. You get the same result when using another tool, like psql?


The answer to your problem may very well lie in your first sentence:

I'm using postgresql 9.0 beta 4.

Why would you do that? Upgrade to a stable release. Preferably the latest point-release of the current version. This is 9.1.4 as of today.


I got to the same point: "what in the heck is that blank value?"
No, it's not a NULL, it's a -infinity.

To filter for such a row use:

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

instead of:

WHERE mytestcolumn IS NULL
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜