V
V
Viktoria Smirnova2018-08-28 07:40:56
PostgreSQL
Viktoria Smirnova, 2018-08-28 07:40:56

Selecting a table from a database, why doesn't it work in a query?

The name of the table at me is hammered in a variable. Tables as you understood are always different. The prepared query defines the desired table. For this I used this:

WITH 
New_table AS (SELECT   table_name
FROM information_schema.tables
WHERE  table_name=?;)
...

but it doesn't work. They write on the forums that you need to use dynamic SQL, but I can’t find it anywhere, how does this query look like? Help with the request, if necessary, I will lay out my entire request.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
asmln, 2018-08-28
@asmln

I suspect that ";" superfluous. Maybe there are other problems with the request. It would be nice to see it in its entirety, to see the error message.
And it's not very clear why choose table_name if you already know table_name and pass it through a parameter.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question