select-into

How can I alter a temporary table with 36 million rows to add a new column?

南楼画角 提交于 2020-03-04 19:39:10
问题 I am working with a temporary table in Netezza that contains the columns id, gender, start_date, and end_date. I want to add a new column to this table that contains a default date of 2019-01-01 for all rows. The table to which I want to add this column is a local temp table, so ALTER TABLE does not work ("Error: Operation not allowed on a temp table"). To get around this, I created a new temp table as follows: DROP TABLE new_temp_table IF EXISTS; GO SELECT id, gender, start_date, end_date,

How can I alter a temporary table with 36 million rows to add a new column?

穿精又带淫゛_ 提交于 2020-03-04 19:39:09
问题 I am working with a temporary table in Netezza that contains the columns id, gender, start_date, and end_date. I want to add a new column to this table that contains a default date of 2019-01-01 for all rows. The table to which I want to add this column is a local temp table, so ALTER TABLE does not work ("Error: Operation not allowed on a temp table"). To get around this, I created a new temp table as follows: DROP TABLE new_temp_table IF EXISTS; GO SELECT id, gender, start_date, end_date,

How to store selection result in to variable in Oracle procedure

我的未来我决定 提交于 2019-12-20 20:40:15
问题 I write a simple procedure. I try to store selection result in variable. I use "SELECT INTO" query but I can not doing this. Example: DECLARE v_employeeRecord employee%ROWTYPE; BEGIN SELECT * INTO v_employeeRecord FROM Employee WHERE Salary > 10; END; 回答1: You have a couple options. You could turn that query into a cursor: DECLARE CURSOR v_employeeRecords IS SELECT * FROM Employee WHERE Salary > 10; v_employeeRecord employee%ROWTYPE; BEGIN FOR v_employeeRecord IN v_employeeRecords LOOP /* Do

SELECT or PERFORM in a PL/pgSQL function

大兔子大兔子 提交于 2019-12-19 13:28:09
问题 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",

Oracle, how to open cursor and select one column of many into a variable

久未见 提交于 2019-12-12 02:02:03
问题 I have a Oracle stored procedure returning a reference cursor. I want to open the cursor before i return it to check a count and throw an exception if need be, but im having trouble with syntax and how im supposed to do this. V_ASN_COUNT NUMBER; OPEN O_CURSOR FOR SELECT column1, -- a bunch of columns column2, COUNT(DISTINCT SI.ASN_NO) OVER (PARTITION BY SI.ASN_NO) AS ASN_COUNT FROM AN_ORDER_INFO OI, AN_SHIPMENT_INFO SI WHERE -- a bunch of criteria OPEN O_CURSOR; LOOP FETCH ASN_COUNT INTO V

Create table under a specific FileGroup WHERE 1=2

烈酒焚心 提交于 2019-12-11 13:02:21
问题 I have an WinForms application which creates tables dynamically based on a given table such as: SELECT * INTO TempTable FROM MyTable WHERE 1=2 I want those Temp tables to be created under a specific filegroup though using the above syntax. The syntax to create the table under a filegroup is: CREATE TABLE [dbo].[TempTable]( [RECORDID] [numeric](10, 0) NOT NULL, --etc etc ) ON [TempFileGroup] TEXTIMAGE_ON [TempFileGroup] Is it possible to use my syntax above to create the table under the

INTO clause is not allowed error

自闭症网瘾萝莉.ら 提交于 2019-12-11 12:29:55
问题 I'm trying a simple SQL select into statement on teradata tables, and following the syntax I found here. The statement is the following: select * into DBNAME.account_backup from DBNAME.account; When I run this code I get the following error: SELECT Failed. 3706: Syntax error: INTO clause is not allowed The two tables have precisely the same format (I copied the SQL which created the first table and pasted it to create the second, changing only the name). Any ideas? Much gratitude 回答1: SELECT

How to INSERT INTO…SELECT with ON DUPLICATE KEY

非 Y 不嫁゛ 提交于 2019-12-11 04:59:47
问题 I have two tables with identical structure. Table A contains all the current ads, Table B contains the archived ads. Column 1 (ad_id) is Primary Key, AI, INT. Table engine is MyISAM. I need to copy all the table A ads preceding a certain date to the archive, table B. My goal is that all fields except ad_id are duplicated, ad_id should get auto-incremented. Here is what I have attempted: INSERT INTO B`(`ad_id`, `ad_advertiser`, `ad_ln`, `ad_expire`) SELECT * FROM A WHERE YEAR( ad_expire ) <=

How can I populate temporary tables, filter them, and then loop through (SQL Server)?

青春壹個敷衍的年華 提交于 2019-12-10 19:46:30
问题 I have a one-time operation I need to perform, and am hoping I can do it with a SQL statement (in LINQPad). I need to grab data from two tables, then insert those vals into another one. Specifically, I need to populate the CustomerCategoryLog table with data for each unique combination of Unit/MemberNo/CustNo from the Customers table, adding the corresponding NewBiz value from the MasterUnitsProjSales table. Pseudo-SQL is something like this: // First, need each unique combination of Unit,

MySQL into outfile formatting

女生的网名这么多〃 提交于 2019-12-08 08:28:28
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? 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