select-into

MySQL into outfile formatting

六眼飞鱼酱① 提交于 2019-12-08 03:36:39
问题 select * INTO OUTFILE 'outfile.txt' FIELDS TERMINATED by ',' LINES TERMINATED BY '\n' from nGrams Is there any way I can modify this query to return each row on one line? 回答1: Seems like thats exactly what it would do already. However, if you are doing this on Windows, you might want to use LINES TERMINATED BY '\r\n' or some crappy text editors (e.g. notepad) might not see \n by itself as a line break 来源: https://stackoverflow.com/questions/13750970/mysql-into-outfile-formatting

There is already an object named 'tbltable1' in the database

南楼画角 提交于 2019-12-05 22:01:32
问题 I am trying to insert data from one table to another with same structure, select * into tbltable1 from tbltable1_Link I am getting the following error message: There is already an object named 'tbltable1' in the database. 回答1: The SELECT INTO statement creates a new table of the name you provide and populates it with the results of the SELECT statement. I think you should be using INSERT INTO since the table already exists. If your purpose is in fact to populate a temporary table, then you

MS Access 2010 SQL Select Into Calculated Column Issue

天涯浪子 提交于 2019-12-02 05:17:11
问题 I have a pretty extensive Union query with calculated columns that I'm trying to just "paste values" into a table through a separate SELECT INTO query. I get the error below when executing the query. Is there any way around this without using VBA? “Calculated columns are not allowed in SELECT INTO statements.” For context: Normally, I'd be able to link up to the union query through PowerPivot in Excel but for some reason PowerPivot does not recognize the union query. If I export the union

SELECT or PERFORM in a PL/pgSQL function

柔情痞子 提交于 2019-12-01 16:30:33
I have this function in my database: CREATE OR REPLACE FUNCTION "insertarNuevoArticulo"(nombrearticulo character varying, descripcion text, idtipo integer, idfamilia bigint, artstock integer, minstock integer, maxstock integer, idmarca bigint, precio real, marcastock integer) RETURNS boolean AS $BODY$ DECLARE articulo "Articulo"%ROWTYPE; BEGIN SELECT * INTO articulo FROM "Articulo" WHERE "Nombre" = $1 AND "idTipo"=$3 AND "idFamilia"=$4; IF NOT FOUND THEN INSERT INTO "Articulo" ("Nombre", "Descripcion", "idTipo", "idFamilia", "Stock", "MinStock", "MaxStock") Values ($1, $2, $3, $4, $5, $6, $7);

Declare row type variable in PL/pgSQL

走远了吗. 提交于 2019-11-30 08:40:19
As I found SELECT * FROM t INTO my_data; works only if: DO $$ DECLARE my_data t%ROWTYPE; BEGIN SELECT * FROM t INTO my_data WHERE id = ?; END $$; Am I right? If I want to get only 2-3 columns instead of all columns. How can I define my_data ? That is, DO $$ DECLARE my_data <WHAT HERE??>; BEGIN SELECT id,name,surname FROM t INTO my_data WHERE id = ?; END $$; get only 2-3 columns instead of all columns One way: use a record variable: DO $$ DECLARE _rec record; BEGIN SELECT INTO _rec id, name, surname FROM t WHERE id = ?; END $$; Note that the structure of a record type is undefined until

Declare row type variable in PL/pgSQL

旧时模样 提交于 2019-11-29 11:34:59
问题 As I found SELECT * FROM t INTO my_data; works only if: DO $$ DECLARE my_data t%ROWTYPE; BEGIN SELECT * FROM t INTO my_data WHERE id = ?; END $$; Am I right? If I want to get only 2-3 columns instead of all columns. How can I define my_data ? That is, DO $$ DECLARE my_data <WHAT HERE??>; BEGIN SELECT id,name,surname FROM t INTO my_data WHERE id = ?; END $$; 回答1: get only 2-3 columns instead of all columns One way: use a record variable: DO $$ DECLARE _rec record; BEGIN SELECT INTO _rec id,

Using temp table in PL/pgSQL procedure for cleaning tables

◇◆丶佛笑我妖孽 提交于 2019-11-29 06:52:09
I'm trying to delete all data related to a user id from a game database. There is a table holding all games (each played by 3 players): # select * from pref_games where gid=321; gid | rounds | finished -----+--------+---------------------------- 321 | 17 | 2011-10-26 17:16:04.074402 (1 row) And there is a table holding players scores for that game #321: # select * from pref_scores where gid=321; id | gid | money | quit ----------------+-----+-------+------ OK531282114947 | 321 | 218 | f OK501857527071 | 321 | -156 | f OK429671947957 | 321 | -62 | f When I try the following SELECT INTO

SQL Server 'select * into' versus 'insert into ..select *

白昼怎懂夜的黑 提交于 2019-11-28 22:20:42
问题 Say table1 and table2 already exist, is there any difference between these queries query1 :- select * into table1 from table2 where 1=1 query2: - insert into table1 select * from table2 回答1: The select * into table1 from table2 where 1=1 creates table1 and inserts the values of table2 in them. So, if the table is already created that statement would give an error. The insert into table1 select * from table2 only inserts the values of table2 in table1. 回答2: The first one (SELECT INTO) will

Using temp table in PL/pgSQL procedure for cleaning tables

≡放荡痞女 提交于 2019-11-28 00:11:57
问题 I'm trying to delete all data related to a user id from a game database. There is a table holding all games (each played by 3 players): # select * from pref_games where gid=321; gid | rounds | finished -----+--------+---------------------------- 321 | 17 | 2011-10-26 17:16:04.074402 (1 row) And there is a table holding players scores for that game #321: # select * from pref_scores where gid=321; id | gid | money | quit ----------------+-----+-------+------ OK531282114947 | 321 | 218 | f

SELECT INTO and “Undeclared variable” error

走远了吗. 提交于 2019-11-27 13:52:38
When I try to execute following query: SELECT id_subscriber INTO newsletter_to_send FROM subscribers I get an error: #1327 - Undeclared variable: newsletter_to_send What is wrong with that query ? INSERT ... SELECT http://dev.mysql.com/doc/refman/5.1/en/insert-select.html INSERT INTO newsletter_to_send SELECT id_subscriber FROM subscribers PS: are you sure you don't need in WHERE clause? MySQL does not support the SELECT ... INTO ... syntax. You have to use the INSERT INTO ... SELECT .. syntax to accomplish there. Read more here.. http://dev.mysql.com/doc/refman/5.0/en/insert-select.html I