Skip to content

Latest commit

 

History

History
121 lines (81 loc) · 1.63 KB

File metadata and controls

121 lines (81 loc) · 1.63 KB

Dialect Differences

Differences between MySQL, PostgreSQL, and SQLite.

JSON Operations

MySQL

// JSON_EXTRACT
Db::jsonExtract('data', '$.name')

// JSON_CONTAINS
Db::jsonContains('tags', 'php')

// JSON_SET
Db::jsonSet('data', '$.status', 'active')

PostgreSQL

// JSON extraction
Db::raw("data->>'name'")

// JSON contains
Db::raw("data @> '{\"tags\": [\"php\"]}'")

// JSON set
Db::raw("jsonb_set(data, '{status}', '\"active\"'::jsonb)")

SQLite

// JSON extraction
Db::raw("json_extract(data, '$.name')")

// JSON contains
Db::raw("json_extract(data, '$.tags') LIKE '%php%'")

// JSON set
Db::raw("json_set(data, '$.status', 'active')")

String Functions

SUBSTRING

// MySQL, PostgreSQL, SQLite
Db::substring('name', 1, 10)

CONCAT

// MySQL
Db::concat('first', ' ', 'last')

// PostgreSQL
Db::raw("first || ' ' || last")

// SQLite
Db::raw("first || ' ' || last")

Date Functions

NOW()

// MySQL
Db::now()  // NOW()

// PostgreSQL
Db::now()  // NOW()

// SQLite
Db::now()  // datetime('now')

DATE_ADD

// MySQL
Db::addInterval('created_at', '1 DAY')

// PostgreSQL
Db::raw("created_at + INTERVAL '1 DAY'")

// SQLite
Db::raw("datetime(created_at, '+1 day')")

Identifier Quotes

MySQL

SELECT * FROM `users`

PostgreSQL

SELECT * FROM "users"

SQLite

SELECT * FROM "users"

Next Steps