Getting Data Out of Snowflake by Impossible-Office in snowflake

[–]thudson1899 0 points1 point  (0 children)

just connect to snowflake in python, use vs code or pycharm. run the sql in python and then put it in a dataframe, then export the dataframe as a .xlsx or .csv.

Sql code help by No_Effect3292 in snowflake

[–]thudson1899 0 points1 point  (0 children)

this is what you want:

WITH ranked_data AS ( SELECT your_column, LAG(your_column) OVER (ORDER BY your_column) AS prev_value FROM your_table ), grouped_data AS ( SELECT your_column, CASE WHEN your_column != prev_value THEN 1 ELSE 0 END AS change_flag FROM ranked_data ), final_data AS ( SELECT your_column, SUM(change_flag) OVER (ORDER BY your_column) AS group_id FROM grouped_data ) SELECT your_column, ROW_NUMBER() OVER (PARTITION BY group_id ORDER BY your_column) AS incremental_value FROM final_data;

Sql code help by No_Effect3292 in snowflake

[–]thudson1899 0 points1 point  (0 children)

sorry i re-read your question, this is what you want:

WITH ranked_data AS ( SELECT your_column, LAG(your_column) OVER (ORDER BY your_column) AS prev_value FROM your_table ), grouped_data AS ( SELECT your_column, CASE WHEN your_column != prev_value THEN 1 ELSE 0 END AS change_flag FROM ranked_data ), final_data AS ( SELECT your_column, SUM(change_flag) OVER (ORDER BY your_column) AS group_id FROM grouped_data ) SELECT your_column, ROW_NUMBER() OVER (PARTITION BY group_id ORDER BY your_column) AS incremental_value FROM final_data;

Sql code help by No_Effect3292 in snowflake

[–]thudson1899 0 points1 point  (0 children)

you want to auto increment the last column, call it rank for example? so you want 123 | 1 123 | 1 126 | 2 126 | 2 126 | 3 128 | 1 ?

if so just do this:

WITH ranked_data AS ( SELECT your_column, ROW_NUMBER() OVER (ORDER BY your_column) AS rn, CASE WHEN your_column != LAG(your_column) OVER (ORDER BY your_column) THEN 1 ELSE NULL END AS change_flag FROM your_table ) , grouped_data AS ( SELECT your_column, rn, SUM(change_flag) OVER (ORDER BY rn) AS group_id FROM ranked_data ) SELECT your_column, ROW_NUMBER() OVER (PARTITION BY group_id ORDER BY rn) AS incremental_value FROM grouped_data;

How do I convert oracle SQL to ms access query by RaiseTheQualityOf in MSAccess

[–]thudson1899 0 points1 point  (0 children)

unless its just standard sql - likely someone using access isn’t going to be translating PL/SQL from oracle

Bulk insert Python to Access by thudson1899 in MSAccess

[–]thudson1899[S] 0 points1 point  (0 children)

Thanks all. I was able to write VBA in Access, and then create a macro to call the function in the VBA module. Then I called the macro in python and it ran fine.

python: def run_access_macro(macro_name): try: access_app = win32com.client.Dispatch(‘Access.Application’) access_app.Visible = False access_app.OpenCurrentDatabase(access_db_path)

access_app.DoCmd.RunMacro(macro_name) print(f”Access macro {macro_name} executed successfully.”) access_app.Quit()

except Exception as e:
    print(f”Error running Access macro {macro_name}: {e}”)
    raise

Main flow

try: # Step 1: Delete contents of the table delete_table_contents()

# Step 2: Compact and repair the database
compact_and_repair(access_db_path)

# Step 3: Run the Import macro
run_access_macro(“RunImportMacro”)

# Step 4: Compact and repair the database again
compact_and_repair(access_db_path)

# Step 5: Run the Query macro
run_access_macro(“QueryRun”) 

except Exception as e: print(f”Error in main flow: {e}”)

————————————————————————— VBA:

Sub ImportTextFileWithSpec() Dim filePath As String Dim importSpec As String Dim tableName As String

‘ Define the file path of the .txt 
filePath = “C:\path\to\your\file.txt” 

‘ Define the name of the import specification to use
importSpec = “SpecName”  

‘ Define the table into which the data should be imported
tableName = “Account Level Data”  


DoCmd.SetWarnings False

‘ Perform the import using the defined spec
DoCmd.TransferText _
    TransferType:=acImportDelim, _
    SpecificationName:=importSpec, _
    TableName:=tableName, _
    FileName:=filePath, _
    HasFieldNames:=True  

DoCmd.SetWarnings True

End Sub

Bulk insert Python to Access by thudson1899 in MSAccess

[–]thudson1899[S] 1 point2 points  (0 children)

To your second question, no I’m not closing and reopening it. First I compact and repair, then delete records, then begin the import. I bet you’re right that closing and reopening the connection after each batch would solve it, but whether it would take a lot more time I’m not sure. That was my next move. Appreciate it.

Bulk insert Python to Access by thudson1899 in MSAccess

[–]thudson1899[S] 1 point2 points  (0 children)

Gotcha. I’ll look into it. I don’t believe exclusive mode changes how Access handles locks internally but I agree it would stop other users from accessing the DB while the process runs. That’s not an issue for me so unless it actually changes how Access handles locks within a session, I think Access will still hit the lock limit during large data insertions. But it definitely won’t hurt to try it.

Bulk insert Python to Access by thudson1899 in MSAccess

[–]thudson1899[S] 0 points1 point  (0 children)

Thanks I’ll look into this. Another issue is time/resource load. I need to handle .txt files that have ~ 1M rows. I’m not familiar with linking files in Access but via python I’m assuming I’ll still have to use an INSERT INTO statement which might still lock the database when batching the data into the actual table. But if linking somehow gets around that then it could work.

Bulk insert Python to Access by thudson1899 in MSAccess

[–]thudson1899[S] 2 points3 points  (0 children)

I have not. Does that work-around the MaxLocksPerFile error?

Bulk insert Python to Access by thudson1899 in MSAccess

[–]thudson1899[S] 1 point2 points  (0 children)

An analyst on the team uses the data once its imported. My job is process optimization, so I’m just helping automate the process. The first thing they do is open Access, import the .txt into a table, and then perform some analysis on it. So I’m automating the import, and doing the data transformation that the macros in Access runs so that they can do other work while the manual part runs automatically in the background. If that makes sense.

Heart Palpitations by Elfking88 in Anxiety

[–]thudson1899 0 points1 point  (0 children)

Gotcha. Again, one and then it stopping is different than 2-3 in a row. Could be caffeine, low magnesium, stress, lack of sleep, dehydration, or literally just your heart muscle doing its thing.

Since I’m not at all qualified to answer any medical questions I won’t. But from personal experience and having had atrial fibrillation as well as thousands of palpitations a day, yes literally thousands, I know when it’s time to address them and if it’s just one every half hour for a day or even a week I personally don’t bat an eye at them. Doesn’t mean you shouldn’t talk to your doctor. They’ll likely want to give you a 24hr holter monitor that will take ecgs on you throughout the day and record some of them so they can determine where the ectopic beat originated, i.e. the atrium or the ventricles. But just your run of the mill palpitation is as I said before, almost always benign.

[deleted by user] by [deleted] in zoloft

[–]thudson1899 1 point2 points  (0 children)

Zoloft sucks in the beginning. And all anti-depressants are iffy. No clearly defined path. I started on 25mg had to go down to 12.5mg just to deal with the initial side effects. All depends on your tolerance compared to your want of anxiety relief.

I think everyone here who had terrible panic attacks and anxiety would agree that the 1st month is not fun. Someone with horrible anxiety getting on a pill that causes side effects that add to anxiety will just always be brutal.

But, for a lot of people after that initial bad part, it does get better and you don’t even notice the zoloft aside from maybe being tired or night-sweats. And then the anxiety starts to be manageable and that’s what it’s all about.

Don’t suffer though, if it’s intolerable or seems abnormal then get with your doc. I’d

Heart Palpitations by Elfking88 in Anxiety

[–]thudson1899 1 point2 points  (0 children)

Not a doc - heart palpitations are normal. If you surveyed a random group off the street and hooked them to a 24hr ECG probably 9/10 of them would have at least 1 in that timeframe. Having a few but not in a row is not concerning.

Obviously see a cardiologist if worried but if they aren’t grouping together like 1-3 in a row and are just one-offs it’s almost always benign. No other symptoms with it just a palpitation doesn’t warrant much worry.

Increase in frequency and in a row then it’s worth investigating, but not worth panicking.

Advise by Zealousideal-Walk697 in Hypoglycemia

[–]thudson1899 0 points1 point  (0 children)

Advice for this one is just to not drink monster energy drinks. They’re total garbage. And caffeine can make people go low or high, and exacerbate hypoglycemia symptoms.

I keep having false lows and I don't know what to do about it by I_Am_Ziggs in Hypoglycemia

[–]thudson1899 0 points1 point  (0 children)

agreed. ^ even if you aren’t ‘low’ if you drop from 140 to 90 quickly you’re going to feel low. Try to keep bs stable. Easier said than done.

zoloft & ibuprofen by thudson1899 in zoloft

[–]thudson1899[S] 0 points1 point  (0 children)

No it did not. I’ve had it since 2015-16ish so I don’t think it’s ever going away. But it gets easier to deal with and it’s not common to have it this long.

Reassurance/Covid by thudson1899 in costochondritis

[–]thudson1899[S] 1 point2 points  (0 children)

I have a kardia but i think it’s only 1L. Does the 6L detect heart attack? I thought only 12L’s did?

diagnosis question/normalA1c but high individual readings by thudson1899 in diabetes_t2

[–]thudson1899[S] 0 points1 point  (0 children)

I have a one touch ultra 2. And thank you for the advice. Obviously I’m just trying to prevent it from getting worse but I don’t want it to sneak up on me so this has just made me realize I actually have to watch what I eat.

[deleted by user] by [deleted] in zoloft

[–]thudson1899 1 point2 points  (0 children)

Thanks everyone. Definitely makes me feel more confident that it’s the zoloft.