{"id":22515074,"url":"https://github.com/rggh/sql","last_synced_at":"2025-03-28T01:53:21.487Z","repository":{"id":121737299,"uuid":"361137404","full_name":"RGGH/SQL","owner":"RGGH","description":"postgres / MySQL / T-SQL notes","archived":false,"fork":false,"pushed_at":"2021-04-29T11:10:48.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-02T03:32:20.884Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RGGH.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-24T10:53:44.000Z","updated_at":"2023-09-26T03:11:15.000Z","dependencies_parsed_at":"2023-03-13T12:25:08.161Z","dependency_job_id":null,"html_url":"https://github.com/RGGH/SQL","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RGGH%2FSQL","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RGGH%2FSQL/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RGGH%2FSQL/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RGGH%2FSQL/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RGGH","download_url":"https://codeload.github.com/RGGH/SQL/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245955201,"owners_count":20699891,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-07T03:28:05.039Z","updated_at":"2025-03-28T01:53:21.468Z","avatar_url":"https://github.com/RGGH.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"### connect as postgres user\n\n    sudo -i -u postgres\n\n\n### run psql\n\n    postgres@rag-laptop:~$ psql\n    psql (12.6 (Ubuntu 12.6-0ubuntu0.20.04.1))\n    Type \"help\" for help.\n\n### list databases\n    \n    postgres=# \\l\n                                      List of databases\n       Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   \n    -----------+----------+----------+-------------+-------------+-----------------------\n     gis       | postgres | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | \n     postgres  | postgres | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | \n     suppliers | postgres | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | \n     template0 | postgres | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres          +\n               |          |          |             |             | postgres=CTc/postgres\n     template1 | postgres | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres          +\n               |          |          |             |             | postgres=CTc/postgres\n    (5 rows)\n\n\n### connect to a database\n    postgres=# \\c suppliers\n    You are now connected to database \"suppliers\" as user \"postgres\".\n\n### create a database\n    postgres=# CREATE DATABASE jml;\n    CREATE DATABASE\n    postgres=# \\l\n                                       List of databases\n        Name     |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   \n    -------------+----------+----------+-------------+-------------+-----------------------\n     gis         | postgres | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | \n     jml         | postgres | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 |\n\n### create a table\n    postgres=# \\c jml;\n    You are now connected to database \"jml\" as user \"postgres\".\n    jml=# CREATE TABLE PRODUCTS (id serial, product varchar(40), price money);\n    CREATE TABLE\n    jml=# \n\n### insert into table\n\n    jml=# INSERT INTO PRODUCTS (product,price) VALUES('jug',29.99);\n    INSERT 0 1\n    jml=# INSERT INTO PRODUCTS (product,price) VALUES('pot',9.99) RETURNING *;\n     id | product | price \n    ----+---------+-------\n      2 | pot     | £9.99\n    (1 row)\n    \n    INSERT 0 1\n\n### select from a table\n    jml=# SELECT product FROM products WHERE price \u003c '29.99';\n     product \n    ---------\n     pot\n    (1 row)\n\n### store ip addresses in a table\n\n    jml=# CREATE TABLE inet_test (  \n    jml(#     address INET\n    jml(# );\n    CREATE TABLE\n\n    #### table created\n\n    jml=# \\d\n                   List of relations\n     Schema |      Name       |   Type   |  Owner   \n    --------+-----------------+----------+----------\n     public | inet_test       | table    | postgres\n     public | products        | table    | postgres\n     public | products_id_seq | sequence | postgres\n    (3 rows)\n    \n    jml=# INSERT INTO inet_test (address) VALUES ('192.168.1.0/24'); \n    INSERT 0 1\n    jml=# INSERT INTO inet_test (address) VALUES ('172.16.11.0/24') RETURNING *; \n        address     \n    ----------------\n     172.16.11.0/24\n    (1 row)\n\n#### Use CIDR notation\n\n    jml=# CREATE TABLE cidr_test (  \n    jml(#     address CIDR\n    jml(# );\n\n\n    INSERT INTO cidr_test (address) VALUES ('192.168.10/24');  \n    INSERT INTO cidr_test (address) VALUES ('192.168.10');  \n    INSERT INTO cidr_test (address) VALUES ('192.168.100.128/25');  \n    INSERT INTO cidr_test (address) VALUES ('192.168.100.128'); \n\n    jml=# INSERT INTO cidr_test (address) VALUES ('192.168.10/24');  \n    INSERT 0 1\n    jml=# INSERT INTO cidr_test (address) VALUES ('192.168.10');  \n    INSERT 0 1\n    jml=# INSERT INTO cidr_test (address) VALUES ('192.168.100.128/25');  \n    INSERT 0 1\n    jml=# INSERT INTO cidr_test (address) VALUES ('192.168.100.128');\n    INSERT 0 1\n    \n    jml=# select * from cidr_test;\n          address       \n    --------------------\n     192.168.10.0/24\n     192.168.10.0/24\n     192.168.100.128/25\n     192.168.100.128/32\n    (4 rows)\n\n\n#### update a row\n\n    motorsport=# select * from f1_teams; \n    \n     id | team_name \n    ----+-----------\n      1 | williams\n      2 | mercedes\n      3 | red bull\n      4 | alfa\n      5 | haas\n      6 | alpine\n      7 | ferrari\n      8 | mclaren\n    (8 rows)\n\n\n    motorsport=# UPDATE f1_teams SET team_name = 'alfa romeo' WHERE team_name = 'alfa';\n    \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frggh%2Fsql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frggh%2Fsql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frggh%2Fsql/lists"}