1

I have the following table which has >13.000 rows.

CREATE TABLE "DBA"."mytable" (
"c1"                    numeric(8,0) NOT NULL,
"c2"                    numeric(2,0) NOT NULL,
"c3"                    numeric(4,0) NOT NULL,
"c4"                    numeric(8,0) NOT NULL,
PRIMARY KEY ("c1","c2","c3","c4") 
)

The following query returns no rows when there are at least two rows that happen to meet the condition:

select * from mytable A where A.c1=229 and A.c3=1

More strangely, a slightly modified (but same) version of the query returns 2 rows as expected:

select * from mytable A where A.c1=229 and A.c3+1=2

Having suspected there is some physical corruption in the db, I have created a new db, created the table with the above code and loaded values from an unload file. The results are the same.

I know all four columns in PK is not good design, but this shouldn't be an excuse for the db to return wrong results. By playing with the column creation order and dropping the PK the problem disappears and reappears.

Does aynbody know a fix or some workaround about this problem? The DB is on a Windows 8 64-bit system, the locale is Turkish.

Thanks

Guner Sen
  • 11
  • 2
  • What happens if you use `integer` instead of `numeric`? As you don't have decimal digits anyway, why bother with `numeric`? –  Apr 19 '18 at 11:18
  • Tested with integer, and it's OK. But type change is not a resolver in my situation there are many db's out there in use. – Guner Sen Apr 19 '18 at 13:58

1 Answers1

0

I remember long ago in the times I used Sybase, that sometimes the table's data get silently corrupted.

The only solution we found was to re-create the table and insert the data again. I'm sorry but that was the only solution we found. So, you could copy the data to another table, then drop and recreate your table, and finally copy the data back.

The Impaler
  • 45,731
  • 9
  • 39
  • 76