Skip to content

Instantly share code, notes, and snippets.

View vbilopav's full-sized avatar
🏠
Working from home

Vedran Bilopavlović vbilopav

🏠
Working from home
View GitHub Profile
select
g.code
from (
select generate_series as code from generate_series(1000, 9999)
) g
left outer join tbl t on g.code = t.id
where
t.id is null
order by
random() limit 1;
CREATE EXTENSION pg_stat_statements SCHEMA public;
# postgresql.conf
shared_preload_libraries = 'pg_stat_statements' # (change requires restart)
pg_stat_statements.max = 10000
pg_stat_statements.track = all
@vbilopav
vbilopav / database-dict-sample.md
Created July 22, 2022 09:45
Sample of database dictionary

Dictionary for database pdd

  • Server: PostgreSQL localhost:5436, version 14.0
  • Local time stamp: 2022-07-15T12:01:44.0784710+02:00
  • Schema: public

Table of Contents

create or replace function companies.search_companies(
_search varchar,
_skip integer,
_take integer
)
returns json
language plpgsql
as $$
declare
_count bigint;
/*
Creates TypeScript models from CSharp models
- TypeScript model is set by config key TsModelsPath
- CSharp models namespace is set by config key ModelNamespace
1) Add to your Program.cs:
if (ModelBuilder.Build(args))
{
return;
}
@vbilopav
vbilopav / JsonValidator.cs
Last active May 23, 2023 11:11
Utility function in C# which validates JSON string against .NET model type by using Newtonsoft Json library.
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
namespace MyNamespace;
public static class JsonValidator
{
public static bool IsJsonValidType(this string json, Type modelType, out string? message)
{
try
@vbilopav
vbilopav / duplicate_foreign_keys.sql
Last active June 12, 2023 08:57
Detect all duplicate foreign keys from public schema and generates a script that drops all duplicates but first.
--
-- Detect all duplicate foreign keys from public schema and generates a script that drops all duplicates but first.
--
with fkeys as (
select
tc.constraint_name,
tc.table_name,
kcu.column_name,
ccu.table_name as foreign_table_name,
select
title,
name,
avg(score)
from movies m
join movies_actors using(movie_id)
join actors a using(actor_id)
join (
select movie_id
from actors join movies_actors using(actor_id)