假設我有兩個表,oldstatistics和統計,新表在時間列不同的約束。用INSERT INTO遷移數據,以便與約束PostgreSQL的侵犯
例如,新表具有以下contraint和舊錶中有違反數據:
CONSTRAINT check_ts_2013_03 CHECK (statistictime >= '2013-03-01 01:00:00+01'::timestamp with time zone AND statistictime < '2013-04-01 02:00:00+02'::timestamp with time zone)
違反假設他們有statistictime「2013年4月1日00及數據:15:00+ 01'
我發現了一些解決方案,SQLite與INSERT OR IGNORE(如果違反約束髮生的行將被跳過,它會繼續),但不是爲POSTGRESQL。
你有什麼建議嗎?
以及可能的[有沒有辦法設置一個選項,即使存在錯誤也會導致PostgreSQL腳本繼續?](http:// stackoverflow。 com/q/14908451/1288184):) – 2015-03-19 09:58:10
@SimoKivistö在你的鏈接問題中指定的答案是使用psql,但這不是我的情況,因爲我在python中使用psycopg2模塊。 – 2015-03-19 10:01:56
@valentin_nasta您可以使用'DO'在普通SQL中運行PL/pgSQL:http://www.postgresql.org/docs/9.4/static/sql-do.html或創建一個存儲函數。 – 2015-03-19 10:03:31