SQL Commands: Difference between revisions

From Fundamental Ramen
Jump to navigation Jump to search
Line 4: Line 4:
! 🎯 Purpose || ⌨️ Command
! 🎯 Purpose || ⌨️ Command
|-
|-
| Connection test (interactive) ||
| Connection test<br>(interactive) ||
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
psql postgres://user@localhost:5432/dbname?sslmode=require -c 'SELECT 1'
psql postgres://user@localhost:5432/dbname?sslmode=require -c 'SELECT 1'
</syntaxhighlight>
</syntaxhighlight>
|-
|-
| Connection test (automatic) ||
| Connection test<br>(automatic) ||
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
PGPASSWORD='1234' psql postgres://user@localhost:5432/dbname?sslmode=require -c 'SELECT 1'
PGPASSWORD='1234' psql postgres://user@localhost:5432/dbname?sslmode=require -c 'SELECT 1'
</syntaxhighlight>
</syntaxhighlight>
|-
|-
| Connection test (container) ||
| Connection test<br>(container) ||
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
psql postgres://user@localhost:5432/dbname?sslmode=require -c 'SELECT 1'
psql postgres://user@localhost:5432/dbname?sslmode=require -c 'SELECT 1'

Revision as of 08:52, 20 October 2026

PostgreSQL

🎯 Purpose ⌨️ Command
Connection test
(interactive)
psql postgres://user@localhost:5432/dbname?sslmode=require -c 'SELECT 1'
Connection test
(automatic)
PGPASSWORD='1234' psql postgres://user@localhost:5432/dbname?sslmode=require -c 'SELECT 1'
Connection test
(container)
psql postgres://user@localhost:5432/dbname?sslmode=require -c 'SELECT 1'

Common Operations

Functions

Postgres MariaDB SQLite
Today

Visiting

Postgres MariaDB SQLite
List tables

show tables;
.tables

CREATE USER

Postgres MariaDB
create user
CREATE USER username WITH PASSWORD 'your_password';
change password

GRANT

Postgres MariaDB
on database to user
GRANT ALL PRIVILEGES
  ON DATABASE operation_center
  TO db_user;
on table to user
GRANT ALL PRIVILEGES
  ON ALL TABLES
  IN SCHEMA public
  TO db_user;

SQLite 3

TODO Command
yyyymmdd to yyyy-mm-dd
SELECT printf('%s-%s-%s',
  SUBSTR(trading_date,1,4),
  SUBSTR(trading_date,5,2),
  SUBSTR(trading_date,7,2)
) FROM short_sell WHERE trading_date='20190605';