You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
createtablegenre(
id serialnot nullprimary key,
genre_name varchar(40) not null UNIQUE
created_date timestamp default current_timestamp);
Insert İşlemleri
insert into game (name,price,popularity,genre_id) values ('Wow',100,1,1);
insert into game (name,price,popularity,genre_id) values ('Metin2',300,10,2);
OrderBy Kullanımı
Büyükten küçüğe
select*from game order by created_date desc;
Küçükten büyüğe
select*from game order by created_date asc;
İç içe Select
select*from sale where user_id = (select id from users where username ='utkucan');
NullIf ve Case
select NULLIF('adasd',logo) from game where id=1;
select* , case when balance =0 then 1000 end from users;
Trigger için Fonksiyon
create or replacefunctionlogfunction() returns trigger as $log_trigger$
begin
IF (TG_OP ='DELETE') THEN
insert into log (username,date,name,operation,price,genre_id,logo,game_id) values (user,now(),OLD.name,'D',OLD.price,OLD.genre_id,OLD.logo,OLD.id);
return OLD;
ELSIF(TG_OP ='UPDATE') THEN
insert into log (username,date,name,operation,price,genre_id,logo,game_id) values (user,now(),OLD.name,'U',OLD.price,OLD.genre_id,OLD.logo,NEW.id);
return OLD;
ELSIF (TG_OP ='INSERT') THEN
insert into log (username,date,name,operation,price,genre_id,logo,game_id) values(user,now(),NEW.name,'I',NEW.price,NEW.genre_id,NEW.logo,NEW.id);
return NEW;
end if;
return null;
end;$log_trigger$ language plpgsql;
Trigger
createtriggerlogt after insert orupdateordeleteon game for each row execute PROCEDURE logfunction();
Postgresql Login
psql -h <host_ip>-U <username>-d game_trnetdb
Show All Connection
select*from pg_stat_activity
where datname ='mydatabasename'