[sr-dev] [kamailio/kamailio] db_postgress: insert_update() with DO NOTHING (#1039)

Julien Chavanton notifications at github.com
Tue Mar 21 04:32:08 CET 2017


There is another option to do it directly in db_postgres constraints "auto detection"

https://www.postgresql.org/docs/9.1/static/catalog-pg-constraint.html

We would search the catalog :
```
select conntype from pg_constraint where conrelid = (select oid from pg_class where relname like 'location_test') and contype = u;
select conntype from pg_constraint where conrelid = (select oid from pg_class where relname like 'location_test') and contype = p;
```
wich would return : `location_ruid_idx_test` or `location_test_pkey`

Then we can save this in the module memory :
```struct constraint {
 char *db_name;
 char *db_table;
 char *unique_contraint;  
 char *primary_key_constraint;
};
```
And use it automatically in the next queries ...
```insert into location_test (ruid, username, domain) values ('1234','jo', 'my dom') on conflict on constraint location_ruid_idx_test do update set ruid='1234', username='jo', domain='my dom';
```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/pull/1039#issuecomment-287967115
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sip-router.org/pipermail/sr-dev/attachments/20170320/d99e3b0f/attachment.html>


More information about the sr-dev mailing list