dimanche 21 décembre 2014

How to create a temporary table using VALUES in PostgreSQL


I am learning PostgreSQL and trying to figure out how to create a temporary table or a WITH declaration that can be used in place of regular table, for debugging purposes.


I looked at the documentation for CREATE TABLE and it says VALUES can be used as a query but gives no example; the documentation for the VALUES clause linked therein does not have an example either?


So, I wrote a simple test as follows:



DROP TABLE IF EXISTS lookup;
CREATE TEMP TABLE lookup (
key integer,
val numeric
) AS
VALUES (0,-99999), (1,100);


But PostgreSQL (9.3) is complaining about



syntax error at or near "AS"



My questions are:




  1. How can I fix the statement above?




  2. How can I adapt it to be used in a WITH block?




Thanks in advance.





Aucun commentaire:

Enregistrer un commentaire