| От | Stefan Becker |
|---|---|
| Тема | Is there a solution for "SELECT OR INSERT" |
| Дата | |
| Msg-id | 000001cb8f54$4a9e3c20$dfdab460$@de обсуждение исходный текст |
| Ответы |
Re: Is there a solution for "SELECT OR INSERT"
|
| Список | pgsql-sql |
given a simply table table like this:
create table MyTabl
(id serial,lname varchar,primary key (id)
)
I am trying to return the Primary-Key for a given
row regardless of the wanted row already being
in the table.
using something like:
select coalesce
( (select id from MyTabl where lname='wanted'), (insert into MyTabl (lname) values ('wanted') returning id)
) as id;
the above doesn't allow the insert..returning even thow
a similar select statement would be okay.
Is there a way to get the ID row OR create a new one in
ONE single statement?
my best regards and thank-you
for your time....
Stefan
В списке pgsql-sql по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера