Skip to content

Instantly share code, notes, and snippets.

@shawalli
Created August 7, 2018 18:14
Show Gist options
  • Save shawalli/ddc9c8ff35e0e2f733eb53cb617361af to your computer and use it in GitHub Desktop.
Save shawalli/ddc9c8ff35e0e2f733eb53cb617361af to your computer and use it in GitHub Desktop.
PostGreSQL Query Cheatsheet

Dump Table Names

All

SELECT
    *
FROM
    information_schema.tables;

Non-PostGreSQL

SELECT
    *
FROM
    information_schema.tables
WHERE
    table_schema != 'pg_catalog';

Dump Column Info From All Tables

SELECT
    table_name,
    column_name,
    data_type 
FROM
    information_schema.columns;

Dump Function

SELECT
    pg_get_functiondef(
        '<FUNCTION_NAME>'::regproc
    );

Important Tables

  • information_schema.tables
  • information_schema.columns
  • information_schema.triggers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment