Thursday, 23 February 2017

Generate the INSERT scripts from a table in PostgreSQL

Question: I want to generate INSERT scripts from a table data.

Answer: We can use the following query to pull the existing data and prepare the INSERT statements.

SELECT 'INSERT INTO schemaName.tableName SELECT
'''||name||''',
'''||value||''';
' from schemaName.tableName ;

1. Change the schema and table name.
2. Add every column as shown in query. The name and value are two columns.

No comments:

Post a Comment