MySQL__PostgreSQL__SQLite比較シート - yokohama/oreshic-record GitHub Wiki
Date: 2023-03-07 17:30:28
SQLiを実行する際の便利な文法なので、一般的なSQLの参考にはならない。
DBMS固有の関数を使わずに、select文を使用。
| MySQL | select distinct table_schema from information_schema.tables; |
| PostgreSQL | select datname from pg_catalog.pg_database; |
| SQLite | - |
さらに上記の結果を1つのカラムにまとめる方法。
| MySQL | select group_concat(distinct(table_schema)) from information_schema.tables; |
| PostgreSQL | select array_to_string(array_agg(distinct(datname)), ',') from pg_catalog.pg_database; |
| SQLite | - |
| MySQL | |
| PostgreSQL | |
| SQLite |
さらに上記の結果を1つのカラムにまとめる方法。
| MySQL | |
| PostgreSQL | |
| SQLite |
| MySQL | select table_name from information_schema.tables where table_schema = '<DB名>'; |
| PostgreSQL | select tablename from pg_catalog.pg_tables where schemaname = 'public'; |
| SQLite | select name from sqlite_master where type='table'; |
さらに上記の結果を1つのカラムにまとめる方法。
| MySQL | select group_concat(distinct(table_name), ',') from information_schema.tables where table_schema = '<DB名>'; |
| PostgreSQL | postgres=# select array_to_string(array_agg(distinct(tablename)), ',') from pg_catalog.pg_tables where schemaname = 'public'; |
| SQLite | select group_concat(distinct(name)) from sqlite_master where type='table'; |
| MySQL | create table users (id int auto_increment, name varchar(255), email varchar(255), password varchar(255), primary key(id)); |
| PostgreSQL | create table users (id serial, name varchar(255), email varchar(255), password varchar(255), primary key(id)); |
| SQLite | create table users(id integer primary key, name string, email string, password, string); |
idをauto incremetする場合。