1

I'm reading through someone's code and I've not seen the % sign used this way before. The line is below:

select "modified" from tabDocType where "name" = %(name)s order by modified desc

It's an sql statement that is supposed to be executed in python but I can't seem to figure out what %(name) does. I know % acts as mod function in math and also used for formatting string but I've never seen in done this way before. Can someone explain what's happening here?

I've looked into string formatting: How can I selectively escape percent (%) in Python strings?

But it doesn't seem like what's happening here has anything to do with string formatting.

Mark
  • 113
  • 7
  • 1
    this is not string formatting, it's parametrized query. – buran Sep 26 '21 at 19:42
  • Could you explain a little bit more? Thank you – Mark Sep 26 '21 at 19:43
  • what DB/package this code use? you can check https://stackoverflow.com/q/1633332/4046632 for example. Note different DB can use different placeholder. Also https://en.wikipedia.org/wiki/Prepared_statement – buran Sep 26 '21 at 19:46
  • See https://stackoverflow.com/a/902836/476; it’s inspired by the Python string formatting syntax, but it’s a separate thing. – deceze Sep 26 '21 at 19:51

0 Answers0