|
SLOSifl posted:Just update all the columns if any of them have changed...or do you have triggers on the table that care if certain columns were touched? In Oracle, you'll generate undo and redo for the rewritten records, fire any triggers, and update all the indexes (including the primary key) - and could generate unexpected issues with child table locking (even if no values change). This scenario usually comes up when you use a ROWTYPE variable to push updates into a table (these statements are transformed into an update against every column). In practice, I'm not sure how much this will impact concurrency, but it result in some unexpected and difficult to debug behavior that should be weighed against convenience.
|
# ? Sep 9, 2014 14:16 |
|
|
# ? Apr 27, 2024 00:09 |
|
Yeah, that’s my worry. I guess I'll go with multiple UPDATE clauses then.
|
# ? Sep 9, 2014 14:25 |
|
Based on the questions you're asking, you'll soon be at the point where the question actually becomes, "What actual problem are you trying to solve?". The trouble with these speculations is that you're not just using them as a theoretical information, but that you're presenting what you think are the solutions when they likely aren't.Gatac posted:"Okay, remember this poo poo we did at the beginning? We're working with that again."...: why isn't it done like this? Is this supposed to be one of those cases where the language wants to force you to clean up your thoughts (and program flow) to the point where you no longer need temp tables to get it done? Or am I just looking in the wrong place? What you say is partially true. Most viable databases are very good at doing what they're supposed to do, and are seemingly awful --- in the sense of optimization --- at doing other things. It can be very common that a hundredfold increase results from using a "proper query" instead of something someone just slapped together "because the right answer appeared". Here, however, it sounds like you're confusing where the processing occurs. The database has to find the rows when it runs the query (which is not necessarily the same time it builds it, and not necessarily all at once). If your purpose is to update said rows, it can be something of a waste of time to do this in two steps. "Find all rows with property X then update them" might make sense getting file folders out of a drawer, but the database is generally smart enough to know to "Find a row with property X and update it before finding the next". You can make this worse with ORDER BY statements and such, but the point is still the same: Don't do things to short-circuit the system that best knows how to interact with the database. Based on your question, it sounds like you want the data to cross over to the application before the processing occurs. While there are situations where this is the only viable approach, it can be relatively painful because of all the networking time that gets added, along with the process and session creations on worker threads. Depending on the application and data sizes, things like memory become doubly troublesome because you get to optimize queries and the handler and everything in the middle. For such a scenario, particularly when there's little choice, you can make use of things like SELECT FOR UPDATE RETURNING. With temporary tables, you may well have issues with naming conflicts, dependent on the database, and there are things like CURSORs, which bring their own headaches. In most cases, however, even with the atomicity requirements in most applications, you can get away with return clauses or UPDATE...SELECT. If you can do things with stored procedures, you'll still likely save over an external application. Gatac posted:Hmm, okay. Different question, is it possible to construct an UPDATE that doesn't actually change a field? I know it's possible to just have it write back what's already in there, but is there a way to avoid any change at all? Basically, I'd like to update a record, but certain fields only need to be changed under certain circumstances. (Using CASE statements when assigning the values.) I could just externalize those into separate UPDATEs wrapped in IF blocks, of course, but is it possible to centralize this into one neat UPDATE? Again, what are you trying to do? I think others have beaten me to it, but touching the row, even with the same value, is bad for transaction logging, triggers, and so forth. You seem to want everything in a single statement, but you should be thinking about things that need to occur "within a single transaction". Multiple updates can appear in a single transaction and you can still roll them all back at once. (There are plenty of examples where that's a bad idea, but yeah.) You're trying to do many things here that are "fighting the database"; this almost always means that you're doing the wrong things. You're taking a few keywords and trying to slew them until they seem to fit a scenario. Instead, think about the problems you're trying to solve and determine how the database permits you to solve them. I don't know how else to describe this, but it just sounds like you're looking at things sideways.
|
# ? Sep 10, 2014 00:40 |
|
PhantomOfTheCopier posted:You're trying to do many things here that are "fighting the database"; this almost always means that you're doing the wrong things. You're taking a few keywords and trying to slew them until they seem to fit a scenario. Instead, think about the problems you're trying to solve and determine how the database permits you to solve them. I don't know how else to describe this, but it just sounds like you're looking at things sideways. Yeah, fair enough. Like I said, I'm a newb at this, and fortunately for everyone involved very much not responsible for any serious work on the database - mostly just curious about this and that as I'm trying to wrap my head around some of the paradigms. This is the thread for stupid questions, right? Still, thanks for the responses, everyone.
|
# ? Sep 10, 2014 16:08 |
|
I have the following piece of Oracle SQL that I need to convert to PostreSQL:code:
Problem is, I don't really understand what this WHERE clause is trying to accomplish. I get that it's trying to establish two dates for a range, but the nested trunc functions is throwing me. Can someone help convert this to Postgres and/or explain what this clause does?
|
# ? Sep 11, 2014 21:12 |
|
Agrikk posted:I have the following piece of Oracle SQL that I need to convert to PostreSQL: Gets anything with a REQUEST_DAY in the previous month - running it today would return August.
|
# ? Sep 11, 2014 21:17 |
|
var1ety posted:Gets anything with a REQUEST_DAY in the previous month - running it today would return August. So trunc(trunc(sysdate,MM)-1,MM) returns August 1 and (trunc(sysdate,MM)-1) returns August 31?
|
# ? Sep 11, 2014 21:38 |
|
Agrikk posted:So trunc(trunc(sysdate,MM)-1,MM) returns August 1 and (trunc(sysdate,MM)-1) returns August 31? Yes, as long as the "MM" is a quoted literal and is not a column from your source object.
|
# ? Sep 11, 2014 21:50 |
|
Agrikk posted:So trunc(trunc(sysdate,MM)-1,MM) returns August 1 and (trunc(sysdate,MM)-1) returns August 31? Here's the first expression computed out pre:trunc(trunc(sysdate,MM)-1,MM) trunc(trunc('2014-09-11',MM)-1,MM) trunc('2014-09-01'-1,MM) trunc('2014-08-31',MM) '2014-08-01'
|
# ? Sep 11, 2014 21:51 |
|
Agrikk posted:I have the following piece of Oracle SQL that I need to convert to PostreSQL: http://www.postgresql.org/docs/9.1/static/functions-datetime.html date_trunc?
|
# ? Sep 11, 2014 23:32 |
|
Thanks for the responses, guys. Turns out just a few more links down google results taugh me the postgresql version of Oracle's trunc is date_trunc. Go figure. The result was: code:
...aaaand beaten
|
# ? Sep 11, 2014 23:34 |
|
When I insert multiple rows with "INSERT INTO table (col1, col2) VALUES (blah, blah), (blah, blah), (blah, blah);" can another database user read the new rows before they are completely inserted? In other words if I insert three new rows, can another user read row1 before i finish inserting row3? I am using PostgreSQL.
|
# ? Sep 15, 2014 21:30 |
|
Shinku ABOOKEN posted:When I insert multiple rows with "INSERT INTO table (col1, col2) VALUES (blah, blah), (blah, blah), (blah, blah);" can another database user read the new rows before they are completely inserted? I wouldn't chance it being atomic, so I would just wrap it in a transaction.
|
# ? Sep 15, 2014 22:04 |
|
Shinku ABOOKEN posted:When I insert multiple rows with "INSERT INTO table (col1, col2) VALUES (blah, blah), (blah, blah), (blah, blah);" can another database user read the new rows before they are completely inserted? In general, no other connections won't see it until that statement commits. There is an notion of a read uncommitted isolation level, but Postgres doesn't actually have it. It does have neat things like serializable snapshot isolation which turns hard to detect race conditions into errors http://www.postgresql.org/docs/9.3/static/transaction-iso.html
|
# ? Sep 15, 2014 22:44 |
|
Pardot posted:In general, no other connections won't see it until that statement commits. Sounds good for my purpose. I will try to change the data producer to use transactions later. (I can't do that now because it's a live data scraper). Thanks all.
|
# ? Sep 16, 2014 07:11 |
|
How do I query on text between two known strings? I have IIS Logs stored on a database and I need to pull out the userid portion of it. Let's say I have data that looks like this: XXXXX;+userid=LOGIN;abcdefg My goal is to pull out the text that exists between +userid= and ;. So in this case I would have LOGIN as my result. Assuming the column name is LOGININFO, I have attempted to write this: code:
Invalid length parameter passed to the LEFT or SUBSTRING function.
|
# ? Sep 17, 2014 00:39 |
|
quote:charindex(';', LOGININFO) Edit: I would recommend solving this problem with baby steps. For example, confirm that your start index is correct SQL code:
Edit2: then fix all your off-by-one errors Sedro fucked around with this message at 01:45 on Sep 17, 2014 |
# ? Sep 17, 2014 01:40 |
|
substring_index(substring_index(LOGININFO,'+userid=',-1),';',1)
|
# ? Sep 17, 2014 11:35 |
|
I'm an SQL scrub who's starting to write somewhat detailed reports. This is quickly getting into things more complex than your basic select and join statements so I need some help. The point of this query is to look at all records in the past three months divided into individual months, then further grouped into each unique combination of sub-business and importer. It will then find a percentage of which of those are of one value vs. another value. Right now just summing up how many of them are 'HOLD' should be fine. This is the query I have now: code:
|
# ? Sep 17, 2014 14:46 |
|
Our Oracle databases are set up to lock accounts after a certain number of failed attempts. This means that anyone who can find the database connection information (without the password) can take down all of our production systems. Is this pretty standard or should there be some other security measure to block the person trying to login, instead of locking the account.
|
# ? Sep 17, 2014 15:50 |
|
One Swell Foop fucked around with this message at 16:44 on Sep 17, 2014 |
# ? Sep 17, 2014 16:25 |
|
Necc0 posted:I understand that my problem is the grouping function is ONLY looking at the 'HOLDS' column so all I'm getting is a bunch of 1s and 0s. How do I get it to sum up all the 'HOLD' values where the month, and var3/var7 fields are equal? code:
I'm not 100% sure but I think the grouping condition on your calculated month field could be the issue, can you try the change above?
|
# ? Sep 17, 2014 16:36 |
|
One Swell Foop posted:
Exactly what I needed, thanks a bunch
|
# ? Sep 17, 2014 16:38 |
|
Is there a way to concatenate a string onto a count(*)? For instance: code:
|
# ? Sep 17, 2014 21:06 |
|
raej posted:Is there a way to concatenate a string onto a count(*)? Use pipes || to concatenate strings. Or you can use a concat() function depending on what you're using.
|
# ? Sep 17, 2014 21:08 |
|
Perfect, thanks!
|
# ? Sep 17, 2014 21:26 |
|
raej posted:Is there a way to concatenate a string onto a count(*)? If you want to get all anal (mssql where the + operator works but have to convert): code:
|
# ? Sep 17, 2014 22:46 |
|
BabyFur Denny posted:substring_index(substring_index(LOGININFO,'+userid=',-1),';',1) Sorry should have mentioned this is SQL Server, substring_index doesn't work. Sedro posted:That's going to resolve to the location of the first semicolon, so your resulting length is probably negative. I managed to get this to work for certain data with a function I wrote. Turns out the "userid" is not always in the same spot and in those cases I kept getting errors. Since I am importing this data into SQL Server via LogParser (as I am working with IIS logs), LogParser actually provides a really simple way of extracting out the userid from the cookie column (LOGININFO in my case). Makes things simpler if I just make an entirely new column for USERID. Oddly enough, this still does not always work! In cases where "userid" is the first text in the cookie column, LogParser just ignores it and a NULL gets written to my new USERID column. Luckily in those cases, since I know where userid is going to be in the data set, I can use charindex/substring to pull out the information and use a simple UPDATE to populate my column. A combination of using LogParser for the bulk of the user_ids and a manual fix for the remaining problematic ones ultimately gives me what I want.
|
# ? Sep 18, 2014 00:13 |
|
Is there an easier way of storing this data? I'm working on a database for my family. I want to store the people who rsvped would be assigned a certain thing ex: Event: Fourth of July year: 2099 Rsvp Supplies John Doe. paper plates Peggy Sue. soda I currently have a table for each holiday ( fourth of July, Christmas etc) An rsvp and supply table for each holiday as the number of people invited depends on the holiday . Currently I query the holiday by year, then merge the rsvp and supply
|
# ? Sep 18, 2014 09:16 |
|
joebuddah posted:Is there an easier way of storing this data?
|
# ? Sep 18, 2014 14:57 |
|
I'm working on an internal, mysql-powered database for one of our users to log workplace accidents. I have the database up and running, and I have the tables and query all set up and good to go. Before I resort to writing my own frontend, I wanted to see if there's anything pre-existing I could use to generate one. Ideally it'd be something simple enough for the (somewhat older) user to get used to. And since the query utilizes several JOINs, it'd be great if the "Add Entry" window of whatever frontend showed the JOINed table's Name column instead of a bunch of IDs. Worst case scenario I'll have to write something up myself. The trickiest part is getting the information into the database. The user has expressed a desire to generate charts and graphs in Excel so I'll use the ODBC drivers to map a connection they can use for that purpose.
|
# ? Sep 18, 2014 22:39 |
|
Karthe posted:I'm working on an internal, mysql-powered database for one of our users to log workplace accidents. I have the database up and running, and I have the tables and query all set up and good to go. Before I resort to writing my own frontend, I wanted to see if there's anything pre-existing I could use to generate one. I haven't used either myself but Xataface and VFront both look like they could be good free options for a web UI over tables. Karthe posted:And since the query utilizes several JOINs, it'd be great if the "Add Entry" window of whatever frontend showed the JOINed table's Name column instead of a bunch of IDs. Worst case scenario I'll have to write something up myself. I think MySQL supports writable views, so you should be able to define a front end over a view rather than just a table to get this behaviour.
|
# ? Sep 18, 2014 23:59 |
|
If I have data that consists of an email address, a severity (low, medium, high, critical) and contact type (phone, chat, email):code:
code:
Help? Agrikk fucked around with this message at 19:26 on Sep 19, 2014 |
# ? Sep 19, 2014 19:23 |
|
a sum(type='chat') does the trick.
|
# ? Sep 19, 2014 19:37 |
|
BabyFur Denny posted:a sum(type='chat') does the trick. So is it as simple as code:
|
# ? Sep 19, 2014 19:49 |
|
Exactly. Some stricter versions of SQL than mySQL might require you to convert the boolean to an int first, dunno. A sum(if(type='chat',1,0)) would work in any case.
|
# ? Sep 19, 2014 20:09 |
|
Well drat... that worked perfectly. Easy as pie. Thanks!
|
# ? Sep 19, 2014 20:54 |
|
I am looking for the proper way, if one exists, to join an application users table and HR table to determine if terminated users have an active application account. The issue is that the HR system has multiple records per user for each job. For users with multiple jobs, 1. If both are active, return either record. 2. If both are terminated, return either record. 3. If there is one active and one termed record, return the active record. This is currently accomplished by exporting the HR table to excel, sorting by Status, and then using a VLOOKUP to pull the needed records. I need to see NULL matches as well, since there are also non-employee users in the application who will not be in the HR table. Obviously a LEFT JOIN will not work since I am then duplicating records for users with multiple jobs like so: code:
|
# ? Sep 23, 2014 19:51 |
|
PapFinn posted:I am looking for the proper way, if one exists, to join an application users table and HR table to determine if terminated users have an active application account. It looks to me like you can solve this pretty easily. Throw this into a cte (Common Table Expression) or a temp table, and slap a RANK() OVER(PARTITION BY USER_CODE, GROUP_CODE, ORDER BY EmploymentStatus), then select WHERE Rank = 1.
|
# ? Sep 23, 2014 20:39 |
|
|
# ? Apr 27, 2024 00:09 |
|
Anaxandrides posted:It looks to me like you can solve this pretty easily. Throw this into a cte (Common Table Expression) or a temp table, and slap a RANK() OVER(PARTITION BY USER_CODE, GROUP_CODE, ORDER BY EmploymentStatus), then select WHERE Rank = 1. Awesome. I'll look into a solution using this method.
|
# ? Sep 23, 2014 22:48 |