python - How do I increment a column variable in postgres where inputs might change the beginning of the variable? -


so have table

create table public.portfolio (   id integer primary key not null default nextval('portfolio_id_seq'::regclass),   name character varying(80) not null,   path character varying(80) not null ); create unique index portfolio_path_key on portfolio using btree ("4"); create unique index portfolio_name_key on portfolio using btree (name); 

and want able input path number followed forward or slash:

123/456/x

where x incremented depending on the 2 numbers given before it. i've considered joining 2 tables or using sequences i'm relatively new postgres , feel i'm missing something.

what have use sequences i'm not entirely sure that's right way it.

if i'm asking user put in first 2 numbers, how can postgres add database after incrementing last number or defaulting 0?

you should select row matches string doing this:

find = "123/456/x".split('/') find = find.pop() # remove 'x' string find = "/".join(find) query_str = "select id, path portfolio path '%s'" % (find, ) 

then query db query_str, parse x path (using path.split("/")) , issue update query incremented x variable. if select query not return rows, issue insert query insert initial value.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -