psql
- User
psql
- Assistant
psqlis the command-line interface for interacting with PostgreSQL, an open-source relational database management system. It allows users to execute SQL commands, manage database objects, and perform administrative tasks directly from the terminal.Here are some common operations and commands used in
psql:Starting
psqlTo connect to a PostgreSQL database using
psql, you can use the following command:psql -U username -d database_name-U username: Specifies the username to connect with.-d database_name: Specifies the name of the database to connect to.
If you want to connect to a local database with default parameters, you can simply use:
psqlCommon Commands
Once you're in the
psqlshell, you can use various commands:-
List Databases:
\l -
Connect to a Database:
\c database_name -
List Tables:
\dt -
Describe a Table (shows columns and their types):
\d table_name -
Execute SQL Queries:
SELECT * FROM table_name; -
Exit
psql:\q
Helpful Options
-
View Help: You can view a list of all
psqlcommands and their usage by typing:\? -
View SQL Syntax Help: For SQL command syntax:
\h
Example Session
-
Start
psql:psql -U myuser -d mydatabase -
List all tables:
\dt -
Query a table:
SELECT * FROM employees; -
Exit:
\q
Tips
-
You can run
psqlcommands in a script by using the-foption:psql -U username -d database_name -f script.sql -
To avoid typing passwords multiple times, you can set the
PGPASSWORDenvironment variable or use a.pgpassfile.
For more information, you can refer to the official PostgreSQL documentation.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- gpt-4o-mini-2024-07-18Compare side by side →
- gpt-4o-mini-2024-07-18Compare side by side →
- gpt-4o-mini-2024-07-18Compare side by side →
- gpt-4o-mini-2024-07-18Compare side by side →
- gpt-4o-mini-2024-07-18Compare side by side →
- gpt-4o-mini-2024-07-18Compare side by side →
- gpt-4o-mini-2024-07-18Compare side by side →