Anasayfa / Database / Postgresql

Postgresql

Postgresql Master Detail Query to Json

Bazen yazdığımız bir sorguyu json olarak çıktı vermek isteriz create table testfatura( id serial primary key not null, fatura_no varchar(10) not null, aciklama varchar(100) not null ); create table testfatura_detay( id serial primary key not null, testfatura_id int not null references testfatura(id), stokkodu varchar(50), stokadi varchar(50) ); insert into testfatura …

Devamını Oku »

Postgresql 13 random tckn generator

Öncelikle plpython3 ‘ü yüklüyoruz sudo apt-get install postgresql-contrib postgresql-plpython3-13 CREATE OR REPLACE FUNCTION random_tckn () RETURNS TEXT AS $$ from random import randint tcno = str(randint(100000000, 1000000000)) list_tc = list(map(int, tcno)) tc10 = (sum(list_tc[::2]) * 7 - sum(list_tc[1::2])) % 10 new_tc = tcno + str(tc10) + str((sum(list_tc[:9]) + tc10) % …

Devamını Oku »

ubuntu server 20.04 install postgresql and remote access

sudo apt-get update sudo apt-get upgrade sudo reboot sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - sudo apt-get update sudo apt-get -y install postgresql   dikkat aşağıdaki işlem veritabanı sunucunuzu tamamen dışarıya açar bilinçli bir şekilde yaptığınızdan …

Devamını Oku »

postgresql find dependent object

https://stackoverflow.com/questions/4462908/find-dependent-objects-for-a-table-or-view   SELECT dependent_ns.nspname as dependent_schema , dependent_view.relname as dependent_view , source_ns.nspname as source_schema , source_table.relname as source_table , pg_attribute.attname as column_name FROM pg_depend JOIN pg_rewrite ON pg_depend.objid = pg_rewrite.oid JOIN pg_class as dependent_view ON pg_rewrite.ev_class = dependent_view.oid JOIN pg_class as source_table ON pg_depend.refobjid = source_table.oid JOIN pg_attribute ON pg_depend.refobjid …

Devamını Oku »