From df47fc3d7da1bd74e165df6f37269b0b8ce2d446 Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Fri, 1 Nov 2024 20:56:26 +0100 Subject: [PATCH] chore(postgresql): dump acquired knowledge --- knowledge base/postgresql.md | 15 +++++++---- snippets/postgres/commands.sh | 20 ++++++++++++++ snippets/postgres/functions.sql | 47 ++++++++++++++++++++------------- snippets/postgres/primer.sql | 46 ++++++++++++++++++++++++++++++-- 4 files changed, 102 insertions(+), 26 deletions(-) diff --git a/knowledge base/postgresql.md b/knowledge base/postgresql.md index 3b9623f..0761579 100644 --- a/knowledge base/postgresql.md +++ b/knowledge base/postgresql.md @@ -47,11 +47,12 @@ EOF chmod '600' ~/'.pgpass' # Set up the per-user services file. +# do *not* use spaces around the '=' sign. cat < ~/'.pg_service.conf' [prod] -host = prod.0123456789ab.eu-west-1.rds.amazonaws.com -port = 5433 -user = master +host=prod.0123456789ab.eu-west-1.rds.amazonaws.com +port=5433 +user=master EOF ``` @@ -137,7 +138,7 @@ CREATE OR REPLACE FUNCTION increment(i integer) RETURNS integer AS $$ BEGIN RETURN i + 1; - END + END; $$ LANGUAGE plpgsql; ``` @@ -153,7 +154,7 @@ AS $func$ BEGIN EXECUTE format('SELECT count(%s) FROM %s LIMIT 2', column_name, table_name) INTO result; RETURN result; - END + END; $func$; SELECT * FROM entries_in_column('vendors','vendor_id'); ``` @@ -234,6 +235,8 @@ psql -h 'localhost' -p '6543' -U 'postgres' -d 'postgres' -W - [How to write update function (stored procedure) in Postgresql?] - [How to search a specific value in all tables (PostgreSQL)?] - [PostgreSQL: Show all the privileges for a concrete user] +- [PostgreSQL - disabling constraints] +- [Hashing a String to a Numeric Value in PostgreSQL]