Last active
April 20, 2020 01:58
-
-
Save achraf-jeday/0e2d34f8a43034b7d4c7f72c4df943ba to your computer and use it in GitHub Desktop.
Postgres useful commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Connect to the Postgres server: | |
psql postgres postgres | |
Create a database: | |
CREATE DATABASE drupal_legacy; | |
Connect to a database: | |
\c drupal_legacy | |
List all tables: | |
\dt | |
Select query: | |
SELECT * FROM opm_ref_document_type; | |
SELECT * FROM opm_ref_commune WHERE code_postal = '94250'; | |
Count rows query: | |
SELECT count(*) AS exact_count FROM users_field_data; | |
List all databases: | |
\l | |
Delete a database: | |
DROP DATABASE IF EXISTS "dev-fo"; | |
Drop a table: | |
DROP TABLE IF EXISTS opm_ref_diplome; | |
Quit CLI: | |
\q | |
Import an SQL file into a database: | |
psql drupal_legacy postgres < global_opm_fo_pgdump.sql | |
Get the last value of a sequence: | |
SELECT last_value FROM pfe_demande_fo_id_seq; | |
Set the value of a sequence: | |
SELECT setval('pfe_demande_fo_id_seq', 1, true); # next value will be 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment