Question

I want to create select Query in Postgresql. my code is

 select * into concat('production.',layer_name)  from concat('staging.',layer_name); 

but there is a problem

ERROR:  "concat" is not a known variable
LINE 20: select * into concat('production.'layer_name)  from concat('...

I can not understand why .

Can anybody help me?

Was it helpful?

Solution

There is a concat() function in Postgres (since v.9.1). Useful for string concatenation possibly involving NULL values. But your syntax is just gibberish to the Postgres parser. It is generally not possible to use values (or return values from a function) as identifiers in plain SQL. You would need dynamic SQL in a plpgsql function for that.

But your example doesn't seem to need either. Do you want to copy rows from one table to another one? If so:

INSERT INTO production.layer_name
SELECT * FROM staging.layer_name
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top