Aldenmarisophia's Profile




  • No need for a subquery here. As I understand, you want to store the checksum of column_a in column_b. As one would expect, Postgres’ md5() function expects a single, scalar argument of string datatype, so:

    UPDATE table SET column_b = md5(column_a) WHERE column_a IS NOT NULL; 

    Note that it would probably be simpler to use a computed column (available in Postgres 12) to store this derived information.

    • 1 answers
    • 0 votes
  • The futur proof version would be to add new tables (or at least one new table) where you could link your project ID with a user ID (or with a first + last name). By doing that, you could have 1 or more people working on a project

    • 3 answers
    • 0 votes
  • Asked on September 1, 2020 in Mysql.
    WITH  cte AS (SELECT id,                 code_name,                CONCAT('[', REGEXP_REPLACE(SUBSTRING_INDEX(code_name, ' ', 1), '[\-\/ ]', ','), ']') code,                SUBSTRING_INDEX(code_name, ' ', -1) name         FROM test) SELECT id,        code_name FROM cte ORDER BY code->>"$[0]" + 0,          code->>"$[1]" + 0,          code->>"$[2]" + 0,          code->>"$[3]" + 0,          name; 


    • 2 answers
    • 0 votes
  • You should use the datatype BIGINT as it allows you to store 8 bytes. The DATE field is generally used for just that, Date and DateTime implementations like LocalDateTime. Since you’re using a LocalDate and subsequently a LocalTime you’re better off just using a DATE type. Your method effectively becomes;

    public static Date getBeginAndEndTime(String time) {          // cache this, it's a thread-safe object     DateTimeFormatter format = DateTimeFormatter.ofPattern("HHmmssSSS");            return LocalTime.parse(time, format).atDate(; } 
    • 1 answers
    • 0 votes
  • Asked on September 1, 2020 in Mysql.

    I would use a correlated subquery here:

    select      t.*,     (         select coalesce(sum(tb.qty), 0)          from wp_tours_tours_bookings tb          where tb.tour_id = t.tour_id     ) as totalbookings from wp_tours_tours t where t.post_id=12 
    • 2 answers
    • 0 votes
  • Asked on September 1, 2020 in Mysql.

    First of all, you might have too many parameters for the mail() function… You are able to have of maximum of five, mail(to, subject, message, headers, parameters);

    As far as the $from variable goes, that should automatically come from your webhost if your using the Linux cPanel. It automatically comes from your cPanel username and IP address.

    $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $from = 'From:'; $to = '[email protected]'; $subject = 'Customer Inquiry'; $body = "From: $name\n E-Mail: $email\n Message:\n $message"; 

    Also make sure you have the correct order of variables in your mail() function.

    The mail($to, $subject, $message, etc.) in that order, or else there is a chance of it not working.

    • 26 answers
    • 0 votes
  • Asked on September 1, 2020 in Mysql.

    It looks like you want:

    select     product,     case when min(plan_week) <> max(plan_week) then 'yes' else 'no' end as week_switch from operations where time_stamp in ('2020-01-01', '2020-03-15') group by product 

    This aggregates the rows by product. Then, the case expression checks if there are (at least) two different values in plan_week, and sets the flag accordingly.

    The where clause is not strictly necessary. You can remove it, depending on whether you want to check two particular dates or the entire dataset.

    • 2 answers
    • 0 votes
  • You can add one object as an array to an existing array as follows:

    [notifications addObjectsFromArray: [NSArray arrayWithObject: object.dictionary]]; 

    Alternatively, instead of arrayWithObject, you can also use the literal notation:

    [notifications addObjectsFromArray: @[object.dictionary]]; 

    You can add even more than one object at a time:

    [notifications addObjectsFromArray: @[object1.dictionary, object2,dictionary]]; 
    • 1 answers
    • 0 votes
  • Asked on September 1, 2020 in iOS.

    The error message is explaining that you must have a Random Access Collection, so that ForEach can iterate through the collection.

    For example, Swift’s Array conforms to RandomAccessCollection protocol, so you could use an array.

    I’d suggest that you read up on collections, either in the Swift documentation or on Apple’s Developer website.

    There are probably a few ways to achieve a solution, but perhaps the easiest method is as follows…

    struct ProgramView: View {          @ObservedObject var programDetail: Program          @FetchRequest(entity: Exercise.entity(),                   sortDescriptors: [NSSortDescriptor(keyPath: \, ascending: true)],     ) var allExercises: FetchedResults<Exercise>          var body: some View {         List {             // in this line you create an array of fetched results             // filtered to contain only exercises for programDetail             let exercisesForProgram = allExercises.filter { $0.program == programDetail }                          ForEach(exercisesForProgram) { exercise in                 Text(!)             }         }     } } 
    • 2 answers
    • 0 votes
  • The while loop keeps execution from proceeding, but the run command doesn’t just wait, but rather it processes events on that thread’s run loop, including the processing of GCD sources, timers, dispatched blocks, etc.

    FWIW, when you’re dealing with an asynchronous method, you would either:

    1. Use completion handler.

      Generally if you have an asynchronous method, in order to reason about the state of the object (e.g. when to dismiss a spinner letting the user know when it’s done), you’d supply a completion handler. (This is assuming that the simple async was a simplification of some more complicated asynchronous pattern.)

      If you really want to have an asynchronous method that asynchronously mutates the object and your app doesn’t currently need to know when it’s done, then make that completion handler optional:

       func updateName(to name: String, completion: (() -> Void)? = nil) {      DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in          self?.name = name          completion?()      }  } 

      Then you can use expectations in your unit tests, which is the standard way of testing asynchronous methods:

       func testUpdateName() {      let e = expectation(description: "Person.updateName")       let person = Person()      person.updateName(to: "Bob") {          e.fulfill()      }       waitForExpectations(timeout: 1)       XCTAssertEqual(, "Bob")  } 
    2. Use a “reader”.

      The previous point is a general observation about testing asynchronous methods. But if you really have a method that is asynchronously mutating an object, you generally would not expose the mutating properties directly, but rather you might use a “reader” method to fetch the property value in a general, thread-safe manner. (E.g. in reader-writer pattern, you might update asynchronously, but your reader would wait for any pending writes to finish first.)

      So, consider a Person that is using the reader-writer pattern:

       class Person {      // don't expose the name at all      private var name: String = ""       // private synchronization reader-writer queue      private let queue = DispatchQueue(label: "person.readerwriter", attributes: .concurrent)       // perform writes asynchronously with a barrier      func writeName(to name: String) {          queue.async(flags: .barrier) {     = name          }      }       // perform reads synchronously (concurrently with respect to other reads, but synchronized with any writes)      func readName() -> String {          return queue.sync {              return name          }      }  } 

      Then the test would use the readName

       func testUpdateName() {      let person = Person()      person.writeName(to: "Bob")      let name = person.readName()      XCTAssertEqual(name, "Bob")  } 

      But you generally would not have a property with asynchronous writes without some way to synchronize reads, too. The example in the question would work if used from main thread only. Otherwise, you’d have race condition.

    • 1 answers
    • 0 votes