SQL Commands: Difference between revisions

From Fundamental Ramen
Jump to navigation Jump to search
Created page with "== SQLite 3 == {| class="wikitable" ! TODO || Command |- | yyyymmdd to yyyy-mm-dd | SELECT printf('%s-%s-%s', SUBSTR(trading_date,1,4), SUBSTR(trading_date,5,2), SUBSTR(..."
 
 
(29 intermediate revisions by the same user not shown)
Line 1: Line 1:
== PostgreSQL ==
{| class="wikitable"
! 🎯 Purpose || ⌨️ Command
|-
| Connection test<br>(host) ||
<syntaxhighlight lang="bash">
PGPASSWORD='****' psql -U user -h localhost -p 15432 -d dbname -c 'SELECT 1'
PGPASSWORD='****' psql postgres://user@localhost:15432/dbname?sslmode=require -c 'SELECT 1'
</syntaxhighlight>
|-
| Connection test<br>(container) ||
<syntaxhighlight lang="bash">
sudo docker exec -e PGPASSWORD='****' -it postgis-ssl psql -U user -d dbname -c 'SELECT 1'
</syntaxhighlight>
|}
== Common Operations ==
=== Functions ===
{| class="wikitable"
! || Postgres || MariaDB || SQLite
|-
| Today
| <syntaxhighlight lang="sql"></syntaxhighlight>
| <syntaxhighlight lang="sql"></syntaxhighlight>
| <syntaxhighlight lang="sql"></syntaxhighlight>
|}
=== Visiting ===
{| class="wikitable"
! || Postgres || MariaDB || SQLite
|-
| List tables
| <pre></pre>
| <pre>show tables;</pre>
| <pre>.tables</pre>
|}
=== CREATE USER ===
{| class="wikitable"
! || Postgres || MariaDB
|-
| create user
| <syntaxhighlight lang="sql">
CREATE USER username WITH PASSWORD 'your_password';
</syntaxhighlight>
| <syntaxhighlight lang="sql">
</syntaxhighlight>
|-
| change password
| <syntaxhighlight lang="sql">
</syntaxhighlight>
| <syntaxhighlight lang="sql">
</syntaxhighlight>
|}
=== GRANT ===
{| class="wikitable"
! || Postgres || MariaDB
|-
| on database to user
| <syntaxhighlight lang="sql">
GRANT ALL PRIVILEGES
  ON DATABASE operation_center
  TO db_user;
</syntaxhighlight>
| <syntaxhighlight lang="sql">
</syntaxhighlight>
|-
| on table to user
| <syntaxhighlight lang="sql">
GRANT ALL PRIVILEGES
  ON ALL TABLES
  IN SCHEMA public
  TO db_user;
</syntaxhighlight>
| <syntaxhighlight lang="sql">
</syntaxhighlight>
|}
== SQLite 3 ==
== SQLite 3 ==
{| class="wikitable"
{| class="wikitable"
Line 5: Line 91:
| yyyymmdd to yyyy-mm-dd
| yyyymmdd to yyyy-mm-dd
|
|
<syntaxhighlight lang="sql">
SELECT printf('%s-%s-%s',
SELECT printf('%s-%s-%s',
   SUBSTR(trading_date,1,4),
   SUBSTR(trading_date,1,4),
Line 10: Line 97:
   SUBSTR(trading_date,7,2)
   SUBSTR(trading_date,7,2)
) FROM short_sell WHERE trading_date='20190605';
) FROM short_sell WHERE trading_date='20190605';
</syntaxhighlight>
|}
|}

Latest revision as of 09:00, 20 October 2026

PostgreSQL

🎯 Purpose ⌨️ Command
Connection test
(host)
PGPASSWORD='****' psql -U user -h localhost -p 15432 -d dbname -c 'SELECT 1'
PGPASSWORD='****' psql postgres://user@localhost:15432/dbname?sslmode=require -c 'SELECT 1'
Connection test
(container)
sudo docker exec -e PGPASSWORD='****' -it postgis-ssl psql -U user -d dbname -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';