jensph
jensph

Reputation: 785

PostgreSQL: How to insert, select, and update values with underscores

I have a table that has a column, file_name. I added file names that contain underscores using insert. Upon select I see spaces where the underscores should be. Apparently the underscore is used for formatting and needs to be escaped.

  1. What is the proper way to insert values with underscores?

  2. How can I update the values with spaces by replacing all spaces with underscores?

  3. What is the proper way to select a row using where when the value has an underscore, such as where file_name = "some_file.txt"

In other words, how and when does the underscore need to be escaped?

Upvotes: 1

Views: 870

Answers (1)

klin
klin

Reputation: 121784

There is no need to escape underscores in string literals in Postgres. See this example. Your case may be caused by a strange behavior of client application. Test your queries in psql.

Upvotes: 1

Related Questions