Retrieving the value of $1, $2 etc. from a Postgres Query
2
votes
1
answer
2874
views
I am currently trying to update/modify a number of SQL queries on a system that does not have any internal Documentation (The developer left on short notice and on bad terms).
I have enabled Query logging in Postgres and have tracked down the Queries in question to be in a number of approximately 30 queries. From there, I plan on running them and seeing what the output is, and then determining which ones need the updates.
The problem is that all of them in the log are in this format (Simplified)
Select t.Col1, t2.Col2, t3.Col3 from Table t
join table2 t2 on t2.Col1 = t.Col1
join table3 t3 on t3.Col1 = t2.Col3
where t.Col1 = $1
and t2.Col3 = $2
...
and t3.Col20 = $15
etc.
For some of the parameters, I've been able to guesstimate what the most likely values are (based on the info in the column it looks up), however there are a few that I've got no idea on what they could be.
I'm not super-familiar with Postgres (more of an MSSQL man myself) nor am I familiar with using parameters/variables in queries. It seems to me these values must be either generated somewhere or held somewhere and must be evaluated at some point in order to run a valid query. As such, either logging the values or logging the input or something similar should be possible so I can then finish what is required.
Hopefully someone can advise how to get the 'real' values of the variables $1,$2, $3 etc.
Asked by TheDemonLord
(193 rep)
Apr 3, 2020, 10:40 AM
Last activity: Apr 26, 2025, 06:04 AM
Last activity: Apr 26, 2025, 06:04 AM