MySQL / PostgreSQL / SQLite比較シート

SQLiを実行する際の便利な文法なので、一般的なSQLの参考にはならない。

データベース一覧

DBMS固有の関数を使わずに、select文を使用。

MySQLselect distinct table_schema from information_schema.tables;
PostgreSQLselect datname from pg_catalog.pg_database;
SQLite

さらに上記の結果を1つのカラムにまとめる方法。

MySQLselect group_concat(distinct(table_schema)) from information_schema.tables;
PostgreSQLselect array_to_string(array_agg(distinct(datname)), ‘,’) from pg_catalog.pg_database;
SQLite

テーブルのカラム一覧

MySQL
PostgreSQL
SQLite

さらに上記の結果を1つのカラムにまとめる方法。

MySQL
PostgreSQL
SQLite

DB名に存在するテーブル一覧

MySQLselect table_name from information_schema.tables where table_schema = ‘<DB名>’;
PostgreSQLselect tablename from pg_catalog.pg_tables where schemaname = ‘public’;
SQLiteselect name from sqlite_master where type=’table’;

さらに上記の結果を1つのカラムにまとめる方法。

MySQLselect group_concat(distinct(table_name), ‘,’) from information_schema.tables where table_schema = ‘<DB名>’;
PostgreSQLpostgres=# select array_to_string(array_agg(distinct(tablename)), ‘,’) from pg_catalog.pg_tables where schemaname = ‘public’;
SQLiteselect group_concat(distinct(name)) from sqlite_master where type=’table’;

テーブル作成

MySQLcreate table users (id int auto_increment, name varchar(255), email varchar(255), password varchar(255), primary key(id));
PostgreSQLcreate table users (id serial, name varchar(255), email varchar(255), password varchar(255), primary key(id));
SQLitecreate table users(id integer primary key, name string, email string, password, string);

idをauto incremetする場合。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

前の記事

ゆっくりffuf

次の記事

sqlmapのクエリー解析