* @copyright 2012 - 2023 Timothy J. Warren * @license http://www.opensource.org/licenses/mit-license.html MIT License * @link https://git.timshomepage.net/aviat/Query * @version 4.1.0 */ namespace Query\Drivers\Pgsql; use Query\Drivers\AbstractSQL; /** * PostgreSQL specific SQL */ class SQL extends AbstractSQL { /** * Get the query plan for the sql query */ public function explain(string $sql): string { return "EXPLAIN VERBOSE {$sql}"; } /** * Random ordering keyword */ public function random(): string { return ' RANDOM()'; } /** * Returns sql to list other databases */ public function dbList(): string { return <<<'SQL' SELECT "datname" FROM "pg_database" WHERE "datname" NOT IN ('template0','template1') ORDER BY "datname" ASC SQL; } /** * Returns sql to list tables */ public function tableList(): string { return <<<'SQL' SELECT "table_name" FROM "information_schema"."tables" WHERE "table_type" = 'BASE TABLE' AND "table_schema" NOT IN ('pg_catalog', 'information_schema'); SQL; } /** * Returns sql to list system tables */ public function systemTableList(): string { return <<<'SQL' SELECT "table_name" FROM "information_schema"."tables" WHERE "table_type" = 'BASE TABLE' AND "table_schema" IN ('pg_catalog', 'information_schema'); SQL; } /** * Returns sql to list views */ public function viewList(): string { return <<<'SQL' SELECT "viewname" FROM "pg_views" WHERE "schemaname" NOT IN ('pg_catalog', 'information_schema') AND "viewname" !~ '^pg_' ORDER BY "viewname" ASC SQL; } /** * Returns sql to list triggers */ public function triggerList(): string { return <<<'SQL' SELECT * FROM "information_schema"."triggers" WHERE "trigger_schema" NOT IN ('pg_catalog', 'information_schema') SQL; } /** * Return sql to list functions */ public function functionList(): ?string { return NULL; } /** * Return sql to list stored procedures */ public function procedureList(): string { return <<<'SQL' SELECT "routine_name" FROM "information_schema"."routines" WHERE "specific_schema" NOT IN ('pg_catalog', 'information_schema') AND "type_udt_name" != 'trigger'; SQL; } /** * Return sql to list sequences */ public function sequenceList(): string { return <<<'SQL' SELECT "c"."relname" FROM "pg_class" "c" WHERE "c"."relkind" = 'S' ORDER BY "relname" ASC SQL; } /** * Return sql to list columns of the specified table */ public function columnList(string $table): string { return <<