postgresqlpostgispgrouting

PostgreSQL: using strings in SQL subquery text in a function


I'm using the pgr_drivingDistance function that requires a SQL subquery as text like so:

pgr_drivingDistance(
'SELECT id, source, target, cost, reverse_cost FROM edges', start_vid, dist, true
)

I would like to subset the edges in the edges table with a where clause like so:

pgr_drivingDistance(
'SELECT id, source, target, cost, reverse_cost FROM edges WHERE col = 'some_string'', start_vid, dist, true
)

The problem is I cannot use single quotes in this case for the string. I tried to escape the quotes of the string with ''', backslash, $$ notations without success.

Is there a way to do this?


Solution

  • There's various ways to escape single quotes (apostrophes) in Postgres string literals: