Renato Dinhani
Renato Dinhani

Reputation: 36746

Copy the result of a query to a table in PostgreSQL inside function

If I execute the following command alone in PostgreSQL, it will insert the result of the query in a table called token_relation, but if I put this inside a PL/PGSQL function, it will try to put inside a RECORD variable.

SELECT * 
INTO token_relation
FROM textblockhastoken  
ORDER BY textblockid, sentence, position 
LIMIT  500;

I want to insert in another table like when the command is execute alone. How I do this inside the function?

Upvotes: 0

Views: 1878

Answers (1)

Glenn
Glenn

Reputation: 9170

Perhaps you want:

INSERT INTO token_relation
  SELECT *
    FROM textblockhastoken  
    ORDER BY textblockid, sentence, position 
    LIMIT  500;

Upvotes: 4

Related Questions