Meta Query - Select the SELECT expression as a string field Sorry, not sure i am in the right place for this question, but anyway:
I was wondering if there is way in PostgreSQL or any other dbms to select the select statement itself? Smthn like this:
SELECT *, $QUERY_EXPRESSION FROM MYTABLE
?
You can use the current_query function:
SELECT *, current_query() FROM generate_series(1, 10) AS n;

 n  |                        current_query                        
----+-------------------------------------------------------------
  1 | SELECT *, current_query() FROM generate_series(1, 10) AS n;
  2 | SELECT *, current_query() FROM generate_series(1, 10) AS n;
  3 | SELECT *, current_query() FROM generate_series(1, 10) AS n;
  4 | SELECT *, current_query() FROM generate_series(1, 10) AS n;
  5 | SELECT *, current_query() FROM generate_series(1, 10) AS n;
  6 | SELECT *, current_query() FROM generate_series(1, 10) AS n;
  7 | SELECT *, current_query() FROM generate_series(1, 10) AS n;
  8 | SELECT *, current_query() FROM generate_series(1, 10) AS n;
  9 | SELECT *, current_query() FROM generate_series(1, 10) AS n;
 10 | SELECT *, current_query() FROM generate_series(1, 10) AS n;
(10 rows)