@ypercubeᵀᴹ when you say you would chain CTEs together to get around that limitation we were discussing yesterday, can you give me a better example of what you mean? I tried to think about how to do it last night but couldn't envision it.
WITH NewItem AS (
... )
MERGE INTO Item USING NewItem ON 0 = 1
WHEN NOT MATCHED THEN
INSERT () VALUES ()
OUTPUT INSERTED.ID, NewItem.SourceID
INTO whatever
WITH NewItem AS (
... ),
ins AS (
INSERT INTO Item
FROM NewItem
RETURNING * -- the POstgres equivalent of OUTPUT
)
INSERT INTO whatever
SELECT ins.ID, NewItem.SourceID
FROM ins JOIN NewItem ON ...
;
My other option besides using a merge is to add a column to the target table in our DB so I can map back to stuff in the import. I expect I'll wind up going that route but we'll see. Gotta talk to my Boss about it
@ypercubeᵀᴹ Heh, heh... right back at you onceandtwice! If our Kiwi friend is allowed use fancy functions, then so can I! Thanks yet again to EB for the second one!
The regex is fine - I mean it is possible that some cretin will be trying to write down his girlfriend's new phone number instead of medical details - but, I think that it is fit for purpose in this case!
@Vérace-getVACCINATEDNOW The second one is much better than the first (fails for numbers of length 10 over 2,147,483,647) but negative integers exist you know.
Ask and you shall receive! Here it is - these, like any regex can become virtually arbitrarily complicated (1, 2) - but the world is your oyster!
My (rather vague it I'm being totally honest) understanding is that simple enough ones like this are not that resource intensive but they can become so with look-aheads/look-backs and what have you... Maybe as a programmer you (or your boss...) might decide that there's diminishing returns on providing error checking for every conceivable error?
However, my solution has the merit of calculating the integer once on data entry - I could, of course, index these generated columns.
Could also ensure that the integer doesn't start with a 0! Also, specify a range - 1 - 999. In fact, most dosages/treatments are normally designed to be able to prescribe in small easy quantities - you would never (caveat - virtually never) get a prescription for 437 mg of something! Also, when designing lab protocols for, say, extracting DNA or protein or... the quantities are normally designed in small units of microliters - 0.5μl being about the limit of reliable pipettability!
So, here's my final stab at this one - I'm not going to try and fix any more errors found by inserting weird and wonderful combinations - it's non-zero starting INTEGERs. It's very finicky - took me a while to get that regex bad boy copied and pasted correctly! The interested reader can add range validation using this: ([-+]?[1-9]|[-+]?[1-9][0-9]|[-+]?[1-9][0-9][0-9])...
These pesky regexes can be very addictive - crack cocaine for nerds - as I'm programming, I keep thinking up more and more complex scenarios and how I would deal with them - but, as written above, there's a diminishing return - unless you eat regexes for breakfast, dinner and tea, getting it right and maintaining these nightmares just wouldn't be worth the effort!
No - it's not weird, well, err... yes, it is, but my regex will lead to it failing! I can see why |0|0| would be a perfectly valid measurement - amount of conc. H2SO4 in blood for example! Or 0|50 - Covid detected vs. TB, say? Have it working for 1 - will get back!
First zero going through OK - second failing?
If anybody can pitch in - it's the 3 fields First zero, Second zero and Both zeroes... works for first Zero but not second - am stumpted!
To hell with this - I've some stuff I've got to do - I'll throw a quick question onto SO and see what I get - there's a few guys over there who are hot stuff when it comes to regexes!
Currently, while creating tables, we create 4 to 5 extra columns with temp names like c0, c1, c2 etc. to be used later when needed and are filled with NULL by default.
This way we don't have to create additional columns when needed. We just rename one of the temp columns create in the first place...
In SQLite, I have a fairly simple data table:
Periods(Start, End)
I'm storing periods with start and end date (stored as integer in seconds), and I'm looking for the information of the highest number of intersections between all periods.
Consider this for easier understanding:
Periods are guest...
Truly appalling design! I saw that before - except where I saw it, they didn't even bother to rename the columns c01... c20 IIRC - a comment was added to the table! Just to reassure everybody, this is a system that runs the rail network of a large European country!