I want to write MERGE query using literal values in BigQuery database.
I tried this: https://stackoverflow.com/a/35659674/5659025 (version for SQL Server) but BigQuery returns the error: "Table-valued function not found"
Is it possible to make it in BigQuery and how?
After our discussion in the commet section, I can suggest you two options:
First, using the INSERT statement. According to the documentation:
Use the INSERT statement when you want to add new rows to a table.
Therefore, you modify the rows in your source table. I have used a dummy data to reproduce it. My source data base was:
In the BigQuery UI, the syntax is as follows:
insert `source_table` (email, content)
select "ale#gmail.com" as email, "add something" as content
or
insert `source_table` (email, content)
select "ale#gmail.com" , "add something"
Notice that I used double quotes because the field I am adding is a String. And the output is as below:
The Second option is to use UNION ALL. I would like to point that with this option your are not updating or modifying your source table, instead you are creating a view with new data added. The syntax is as below:
SELECT 'aleee#gmail.com' , "add something 2" UNION ALL
--#if you want to add more rows to your view, you will need to write another
--#select 'email#gmail.com.br', "something " UNION ALL
SELECT * FROM `test-proj-261014.sample.foobar`
I hope it helps.
Related
What I am trying to achieve is to add tables and columns descriptions programmatically to a Power BI dataset.
For this reason, I use Server Analysis Services to get access to the metadata.
I run a simple request:
select *
from $System.TMSCHEMA_PARTITIONS
As a result, I get a table with columns names:
ID
TableID
Name
Description
....
Now I want to select where the "Description" is empty.
select *
from $System.TMSCHEMA_PARTITIONS
where Description IS NULL
But I can't, I always get a syntax error:
Query (3, 7) The syntax for 'Description' is incorrect.
SQL reads it as a command and I don't know how to avoid it.
I have tried adding quotes and double quotes to the name of the columns, I tried adding a table reference and all of these combined, but nothing helps.
It works for "TableID" for example.
This one works:
select *
from $System.TMSCHEMA_PARTITIONS
where len([Description]) = 0
I'm using PostgreSQL server on my Windows.
I have created table user(id, name, age) and inserted some data there.
When I'm trying to retrieve that data via SELECT ALL FROM user I'm getting only the rows count and just plain nothingness.
How it looks like in psql CLI:
...and I'm also receiving empty object array as query result in my nodejs app:
Postgres supports SELECT ALL as a synonym for SELECT -- as a two words syntax parallel to SELECT DISTINCT. The ALL does nothing.
In addition, Postgres -- unlike other databases -- allows a SELECT to select no columns.
So:
SELECT ALL
FROM user;
Selects all the rows from user but no columns. In general, you would instead write:
SELECT *
FROM user;
to see the contents of the rows. If you want to be verbose, yo could use:
SELECT ALL *
FROM user;
But that is used somewhere close to never in practice.
You specified that you want the data from the column named "all". To get data from all columns you need to specify them all or use the asterisk symbol like so:
SELECT * FROM "user";
I'm new to SSIS packages. I have to run a INSERT query which will be result on an SELECT query.
1) I will run the select query using ODBC source and it will return 6 columns and one of them will be the INSERT query.
I tried putting the query in Flat file destination(.sql extension) it comes out to be fine but cannot fetch it I don't know why might be because of it is dynamic insert query.
Can anyone help me how can I do that?
From your SELECT query, store the value of the column containing the INSERT query in a package variable. Then for your INSERT query, choose the "query from variable" option and use the variable as the source.
This tutorial shows how to store the result of a select query in a variable.
Using SQL Server Management Studio is there a way I can select one or more rows in the grid of select results and have SQL Server Mangement Studio generate one or more insert statements (one for each row selected) which would insert that data into a table with the same schema?
Edit: I know how to create one manually, but I was hoping there would be something that would create it automatically for me. If you are familiar with Toad there is a way to have Toad generate inserts based on data in the results pane and I was hoping SSMS had an equivalant function.
Try to save the query result into a disposable table.
For example:
SELECT * INTO disposable_customer_table FROM customer_table WHERE id IN (in range of something)
Then do a db -> Tasks -> Generate Scripts.
Select specific database objects.
Choose disposable_customer_table from the list of table names.
Choose Save to file.
Make sure to do an Advance setup and select "Data only" from the 'Types of data to script'.
Tweak the result file and rename the disposable_customer_table back to the original table name.
Clean it up and drop the disposable_customer_table.
select 'insert into tableB values (', tableA.x ,',',tableA.y,',',tableA.z,')' from tableA
I think you have two options here:
Create your inserts manually. For instance:
select Name, Surname,
'insert into Person (Name,surname) values ('''+Name+''','''+Surname+')'
from Person
This gets you the results and, in the last column, the insert script for the row. You can then select and paste it in an Editor window.
Right click on the db -> Tasks -> Generate Scripts. Press then Advance and select "Data Only" (Default is Schema Only).
Perform your query and right click on the blank area where the column headers meet the row number in the Results view.
You can then select Script Grid Results:
I am trying to import a large CSV file into a MySQL database. I have loaded the entire file into one flat table. i can select the data that needs to go into separate tables using select statements, my question is how do i copy the results of those select queries to different tables. i would prefer to do it completely in SQL and not have to worry about using a scripting language.
INSERT
INTO new_table_1
SELECT *
FROM existing_table
WHERE condition_for_table_1;
INSERT
INTO new_table_2
SELECT *
FROM existing_table
WHERE condition_for_table_2;
INSERT INTO anothertable (list, of , column, names, to, give, values, for)
SELECT list, of, column, names, of, compatible, column, types
FROM bigimportedtable
WHERE possibly you want a predicate or maybe not;
The answer from Quassnoi was the one I was looking for. Please observe that if new_table_1 doesn't exist yet the "INSERT INTO" statement has to be replaced with a "CREATE TABLE" statement.