13

Working with databases, I sometimes have to write requests which create data (alias add/insert...) or update it, if it already exists.

... and I never know how I should name such an action.

Isn't there some terms meaning specifically this ?
While it could help, I'm not particularly expecting something specific to database manipulation, but rather a more generic term, like "populate", "Ensure", "assert", or... well, I have no idea what term would have such meaning.

Is there anything meant for this ?

  • 4
    Is there an example sentence of how you would like to use this term that isn't related to naming a software function? The "update an entry, or create it if it doesn't exist" seems to me to be something specific to programming. If you were telling a person to do this action, you might say "Make sure Mr. Jone's current address is in the ledger. If it's not already in there, make a new entry for him.". You wouldn't necessarily use a single word to mean update/create. – ColleenV Jul 6 '17 at 14:27
  • 3
    If you're designing an API, keep in mind that there are existing APIs with methods designated for doing specifically that, and they don't use any fancy word for it - see Laravel's updateOrCreate(). – rhino Jul 6 '17 at 21:44
  • 2
    I'm voting to close this question as off-topic because it is not a language question for learners but it's specific to computer programming. – Mari-Lou A Jul 7 '17 at 7:21
  • 2
    @Mari-Lou While the answers tend to confirm this idea, note that my question was NOT intended to be IT specific at all. When you ask "is this a question for learners ?", I wouldn't say that, of course, but according to the stack-exchange descriptions, I had to choose between posting here, or in "English language & usage", whichs is "for linguists, ethymologists & serious english language enthusiasts" Well, when it comes to language, I'm quite enthusiast... but I remain french, and wouldn't consider myself an english professionnal. Shall I consider myself serious enough next time ? – Balmipour Jul 7 '17 at 8:16
  • 2
    I don't think this question should be closed. It does tread pretty close to the line but it doesn't go over because it's explicitly asking for a general term and not one specific to programming. The way folks choose to answer shouldn't make the question off-topic. There are plenty of on-topic questions that are answered "There is no such word". I think it would help keep the answers more focused if the question had a non-programming situation where the term might be used. – ColleenV Jul 7 '17 at 12:04
3

When writing code, I tend to use the word "write" in this case. When I do that, I try to use the word "read" as the opposite (getting information from the database). I've also been known to use "load" and "save", but the problem with "save" is that there is no "save as", so the concept of File / Open and File / Save doesn't always make things clear.

UPDATE:

I went searching and the technical term is "persist", as in you "persist" to a "datastore" (either a database or a file or anything else where data is stored). As far as I know, nobody has (yet) used persist to only mean "update" or "insert". It isn't as common as "save" or "write", and the technical meaning isn't one you'll find in most dictionaries, but at least it is a real English word that native speakers will know and understand.

"write" was used as "update" in file modes: r = read, w = write, a = append.

So I guess I had better go back and change write to persist in the code I wrote yesterday.

  • 1
    Persist and write sound pretty good to me. Persist sounds very 'ORM-ish', though, but it's clearly more focused on the goal (save data) than the means. Write sounds more interesting outside of IT to me, where I'd think of it as "create". I don't imagine myself "persisting" my shopping list on a post-it ^^ – Balmipour Jul 6 '17 at 22:08
35

"Upsert" is sometimes used in this context to mean "Update the row(s) that already exist, and insert the row(s) that do not already exist."

You might not find "upsert" in a dictionary. I have seen "upsert" used in computer source code (and have used it myself). I have also seen "upsert" in documentation that teaches how to write computer source code, such as for IBM, Microsoft Azure, Microsoft T-SQL, MongoDB, PostgreSQL, and Salesforce.

Wikipedia explicitly suggests that in some dialects of SQL, "merge" is a synonym for "upsert".

  • 1
    Damn, I just had I named my requests "updadd_xxx" :p I Think I already read this, indeed. Yet, it's clearly DB focused. – Balmipour Jul 6 '17 at 21:55
8

Computer languages have to be very specific, so dialects of SQL sometimes have specific key words for this. I think Oracle uses MERGE, MySQL uses REPLACE, etc. (I haven't used either in a while so I may have those mixed around.)

I can't think of a word for this in general English because outside of information processing and record keeping, the two ideas are too far apart. You wouldn't normally say, "I will replace the gutters on my house, or if I don't presently have a house I'll build one." Or, "You should change the oil in your car every 7,000 miles, or if you don't have a car you should buy one." In general, updating a thing is a very different idea from acquiring a new thing.

But in record keeping, whether on a computer or on paper, it makes a lot of sense to say, for example, "Add 2 to the inventory count for this item. If there is no inventory record, create a record with a count of 2." I'm hard pressed to think of examples outside record-keeping. Maybe some one on here can think of an example.

I think the conventional thing to say in data processing, outside of contexts where the language has a specific keyword, is "create/update".

3

The word for the property of an action where doing it multiple times has the same outcome as doing it a single time is idempotence.

For example, if you have a remote control on your keychain that locks your car, and you want to ensure that your car is locked (but aren't sure if it already is), you could press the lock button one or more times, because you know that it idempotently locks your car. However, a retracting ballpoint pen isn't idempotent, because clicking it multiple times could leave it in either state.

"Upsert" is a better answer for the database-specific operation you're talking about, but "idempotent" applies to actions in general. It probably wouldn't be understood outside of technical or mathematical contexts though.

More info on SO: https://stackoverflow.com/questions/1077412/what-is-an-idempotent-operation

  • 1
    Even though this is a technical term, I think it's a really interesting contribution that isn't typically what a programmer might use in this situation. The Wikipedia link to idempotence (or some other reference) might be a good addition to your answer. – ColleenV Jul 10 '17 at 16:43
2

If talking about a physical object to be used, "have a [THING] on hand", "have a [THING] ready."

In a technical context, talk about the desired final state? "The database should be populated with [DATA]", "The database should contain the following [DATA]", "Make sure [PACKAGE] is installed."

  • This rewording/example, and the notion of "desired final state" seem relevant to me. – Balmipour Jul 6 '17 at 22:54
0

I am not familiar with SQL but it looks like you treat records like key-value pairs and all keys are present with some default or empty value initially i.e. inserting new key with default/empty value is of no use generally.

If I am correct it would be sensible in some situations to use "set" or "assign" if it is appropriate for nouns which you want to use.

0

Any time I have written a procedure that may either insert a new record or update an existing one depending on circumstances, I have named it using the verb save.

protected by Community Jul 6 '17 at 21:36

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.