Use LIMIT to specify top 20 rows, but I think you need to sort them using ORDER BY clause first. We can insert a single row or multiple row values at a time into the particular table. I don't like that nested dblink, but AFAIK I can't reference to tblB in dblink_exec body. One can insert one or more rows specified by value expressions, or zero or more rows resulting from a query. In PostgreSQL, the INSERT command is used to insert new rows into a table. To do so, run the \dt command: \dt Let’s say we need to insert data into the teaminfo table. If my understanding is correct (postgres has tbla and dbtest has tblb and you want remote insert with local select, not remote select with local insert as above): psql dbtest Step 1: Select a Table Using \dt Command Firstly, select a table where you want to insert the data. One can insert a single row at a time or several rows as a result of a. I just saw your revised question (closed as duplicate, or just very similar to this). The PostgreSQL INSERT INTO statement allows one to insert new rows into a table. You can make it as prepared statement if you want and it works as well: PREPARE migrate_data (integer) AS PostgreSQL has record pseudo-type (only for function's argument or result type), which allows you query data from another (unknown) table. 1 Have never done it with PostgreSQL, but shouldn't it look like INSERT INTO widgets SELECT NULL, mapid, 'Bupo' FROM maptags WHERE maplicense '12345' raina77ow at 17:50 Thanks raina77ow ( 1) - I'm not sure if that's what it should be. INSERT INTO tblB (time) VALUES (5000), (2000) ĬREATE TABLE tblA (id serial, time integer) įROM dblink('dbname=dbtest', 'SELECT id, time FROM tblB') For example: psql dbtestĬREATE TABLE tblB (id serial, time integer) The following SQL copies Suppliers into Customers (the columns. As Henrik wrote you can use dblink to connect remote database and fetch result. The INSERT INTO SELECT command copies data from one table and inserts it into another table.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |