0

I know about autoincrement, and that I might be better off doing a table of its own for this, but for some specific performance reasons I would prefer not to.

I have a row looking like this:

id,log
1 | 1:345;2:2345;3:234

Is there ANY way where I with a single SQL update can add X to the log column, and automatically a '4' as the log entry's id?

2
  • Answer = yes...string functions can pull that off for you (might be a bit ugly?). What Database are you on? String syntax differs between SQL flavours Commented Jan 30, 2014 at 22:44
  • mysql currently, but at some point I wanna move it to nosql like mongodb or similar - but right now i dont wanna mess with a lot of software (just code, and I was curious :)) Commented Jan 31, 2014 at 2:17

2 Answers 2

2

From your example I can't be entirely sure, but it looks like you don't even need the index numbers, i.e.

id | log
1  | 345;234;234

So you can simply add the entry, optionally prefixed with a ;. Later, any code can interpret the log contents by splitting on ;.

Sign up to request clarification or add additional context in comments.

1 Comment

yeah you are completely right, what a nobrainer... Just got caught up in having it in a single field. Explode + count will do :)
0

how about build a new table like this:

my_log
-------
id
sub_id
val

and populate it with all the proper parsed values -

then query from here to rebuild the string if needed, otherwise throw out the original table completely - terrible design.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.