Difference between revisions of "PostgreSQL"

From WhyAskWhy.org Wiki
Jump to: navigation, search
(Stub page)
 
m (Added commands for logging in, showing databases and tables.)
Line 3: Line 3:
  
 
== Character length restrictions ==
 
== Character length restrictions ==
 +
  
 
== Using comments ==
 
== Using comments ==
 +
 +
 +
== Login ==
 +
 +
This is probably not the ''best'' way, but it's what I've learned to do so far:
 +
 +
<syntaxhighlight lang="bash" >
 +
sudo su postgres
 +
psql
 +
</syntaxhighlight>
 +
 +
 +
== Connect to a database ==
 +
 +
<code>\c database_name</code>
 +
 +
 +
== Show all databases ==
 +
 +
* <code>\list</code>
 +
* <syntaxhighlight lang="sql">
 +
SELECT datname FROM pg_database WHERE datistemplate = false;
 +
</syntaxhighlight>
 +
 +
 +
== Show all tables in the current database ==
 +
 +
* <code>\dt</code>
 +
* <syntaxhighlight lang="sql">
 +
SELECT table_schema,table_name FROM information_schema.tables ORDER BY table_schema,table_name;
 +
</syntaxhighlight>
 +
  
 
== Create a database ==
 
== Create a database ==

Revision as of 10:50, 10 September 2014


Character length restrictions

Using comments

Login

This is probably not the best way, but it's what I've learned to do so far:

sudo su postgres
psql


Connect to a database

\c database_name


Show all databases

  • \list
  • SELECT datname FROM pg_database WHERE datistemplate = false;
    


Show all tables in the current database

  • \dt
  • SELECT table_schema,table_name FROM information_schema.tables ORDER BY table_schema,table_name;
    


Create a database

Create a user for that database with full privileges to it

Reset password for user account

Import or run SQL statements from file

Insert a new row

Update field

Delete row

Delete user account

Delete database

Resetting the root user account

Viewing privileges granted to a user

References