換資料庫真的好機掰,會有一堆未知問題,見招拆招,紀錄於下
LIMIT OFFSET
/* MySQL */
SELECT * FROM abc WHERE status=1 ORDER BY create_time DESC LIMIT 0 , 10
/* PostgreSQL */
SELECT * FROM abc WHERE status=1 ORDER BY create_time DESC LIMIT 10 OFFSET 0
# UPDATE 不能加 ORDER BY and LIMIT
/* MySQL */
UPDATE abc SET aaa=1 WHERE id<=100 ORDER BY status DESC LIMIT 10
/* PostgreSQL */
/* 若有需求要用子句解決 */
UPDATE abc main SET aaa=1
FROM
( SELECT id FROM page_builder WHERE id<=100 ORDER BY status DESC LIMIT 10 ) sub
WHERE main.id = sub.id
PHP
$re = pg_query($conn, "INSERT INTO foo (bar) values (123);");
$re = pg_query("SELECT lastval();");
$row = pg_fetch_row($re);
$insert_id = $row
[0];
$re = pg_query($conn, "INSERT INTO foo (bar) values (123);");
$re = pg_query("SELECT lastval();");
$row = pg_fetch_row($re);
$insert_id = $row
[0];[……]