WITH s AS (
SELECT id FROM beta.kitaplar WHERE kitap = 'asdasd'
),
i AS (
INSERT INTO beta.kitaplar ("kitap")
SELECT 'asdasd'
WHERE NOT exists (SELECT 1 FROM s)
RETURNING id
)
SELECT id FROM i
UNION ALL
SELECT id FROM s