Alternative SQL

Ertan Küçükoğlu <[email protected]>
Newsgroups gmane.comp.db.postgresql.sql
Message-ID <[email protected]>
Hello,

I am using PostgreSQL 10.1 64bit on Windows 10 x64 system.

My database have following tables in it:
robox=# \dt
              List of relations
 Schema |        Name         | Type  | Owner
--------+---------------------+-------+-------
 public | aciliskapanis       | table | robox
 public | ameliyathaneler     | table | robox
 public | ameliyatlar         | table | robox
 public | errorlog            | table | robox
 public | guncellemetablolari | table | robox
 public | hastalar            | table | robox
 public | kaphareketleri      | table | robox
 public | kullanici           | table | robox
 public | malzemeler          | table | robox
 public | params              | table | robox
 public | personel            | table | robox
 public | sayimbaslik         | table | robox
 public | sayimdetay1         | table | robox
 public | sayimdetay11        | table | robox
 public | sayimdetay12        | table | robox
 public | sayimdetay2         | table | robox
 public | sayimdetay3         | table | robox
 public | sayimmakinalari     | table | robox
 public | sayimyazdir         | table | robox
 public | sifirlamalar        | table | robox
 public | updates             | table | robox
(21 rows)

I am using following SQL:
select 'aciliskapanis', max(kayitzamani) from aciliskapanis where serino =
'00000000de7de681'
union
select 'sayimbaslik', max(kayitzamani) from sayimbaslik where serino =
'00000000de7de681'
union
select 'sayimdetay1', max(kayitzamani) from sayimdetay1 where serino =
'00000000de7de681'
union
select 'sayimdetay11', max(kayitzamani) from sayimdetay11 where serino =
'00000000de7de681'
union
select 'sayimdetay12', max(kayitzamani) from sayimdetay12 where serino =
'00000000de7de681'
union
select 'sayimdetay2', max(kayitzamani) from sayimdetay2 where serino =
'00000000de7de681'
union
select 'sayimdetay3', max(kayitzamani) from sayimdetay3 where serino =
'00000000de7de681'
union
select 'errorlog', max(kayitzamani) from errorlog where serino =
'00000000de7de681'
union
select 'kaphareketleri', max(kayitzamani) from kaphareketleri where serino =
'00000000de7de681'
union
select 'sifirlamalar', max(kayitzamani) from sifirlamalar where serino =
'00000000de7de681'

Above SQL gives me following result and this is what I wanted. 
?column?	max
sayimdetay2	2018-01-13 23:24:29
errorlog	2018-01-14 00:08:56
sayimbaslik	2018-01-14 00:10:36
sifirlamalar	2018-01-13 23:19:07
sayimdetay11	2018-01-13 23:15:58
sayimdetay1	2018-01-14 00:10:42
sayimdetay3	2018-01-13 23:19:20
aciliskapanis	2018-01-14 00:12:44
sayimdetay12	2018-01-14 00:13:11
kaphareketleri	2018-01-14 00:13:33


But, it is not dynamic. Meaning, I am not using information in
guncellemetablolari table. guncellemetablolari table holds table names as
records that needs to be queried in my database. These records may change in
time. What I would like is an SQL (not a database function, if possible)
which gives me same result as above using records in guncellemetablolari
where guncellenir column is false. 

robox=# \dS guncellemetablolari;
Table "public.guncellemetablolari"
   Column    |  Type   | Modifiers
-------------+---------+-----------
 adi         | text    | not null
 guncellenir | boolean |
Indexes:
    "guncellemetablolari_pkey" PRIMARY KEY, btree (adi)


robox=# select * from guncellemetablolari;
      adi       | guncellenir
----------------+-------------
 ameliyatlar    | t
 hastalar       | t
 malzemeler     | t
 personel       | t
 aciliskapanis  | f
 sayimbaslik    | f
 sayimdetay1    | f
 sayimdetay11   | f
 sayimdetay2    | f
 sayimdetay3    | f
 sayimyazdir    | f
 errorlog       | f
 kaphareketleri | f
 sifirlamalar   | f
 sayimdetay12   | f
(15 rows)

Any help is appreciated.

Thanks & regards,
Ertan Küçükoğlu
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.