Questions tagged [syntax]

The set of rules that define the combinations of symbols that are considered to be correctly structured for that language.

Filter by
Sorted by
Tagged with
0 votes
2 answers
33 views

MariaDB gives syntax error with empty near-string

Im using MariaDB 10.24.8 on Linux and I'm encoutering this syntax error which has been stumping me for the last few hours: ERROR 1064 (42000) at line 7: You have an error in your SQL syntax; check the ...
Fnununkslit's user avatar
0 votes
0 answers
47 views

I can't find syntax error from a PostgreSQL query

A similarly structured query works on Fiddle but I get a syntax error at or near "AND" LINE 9: AND h.paivamaara BETWEEN '2020-12-03'::date AND ... ^ and I ...
jvkloc's user avatar
  • 133
0 votes
2 answers
69 views

How do I identify the SQL server brand via SQL queries

A 3rd party API exposes a endpoint which accepts "SQL" queries. Their examples are simple SELECT statements, however I want to write more complicated queries. They do not specify which SQL ...
yeerk's user avatar
  • 101
0 votes
1 answer
51 views

PostgreSQL create database with parameter syntax error

I have the following function for creating a PostgreSQL database with psycopg: def create_database() -> None: """A function for creating a PostgreSQL database.""" ...
jvkloc's user avatar
  • 133
0 votes
1 answer
44 views

Efficient PostgreSQL query syntax for duplicating the result

Assuming I have the following PostgreSQL query: SELECT ( SELECT SUM (t.customers) FILTER ( WHERE id = 1 AND date BETWEEN %(start)s AND %(stop)s ...
jvkloc's user avatar
  • 133
1 vote
1 answer
69 views

What function do I need to get single quoted constants in the generated SQL? The code generator wraps the single-quoted output in double quotes

I wanted to create a view that sums a table common to a number of schemas, as expressed here, and includes the schema name or a derived expression as a column, so I created a view that includes the ...
vfclists's user avatar
  • 1,041
2 votes
1 answer
209 views

Common Table Expression syntax

Considering a query with CTEs: WITH cte_0 AS ( SELECT SUM(col_0) FROM table_0 WHERE condition_00 AND condition_01 ), cte_1 AS ( SELECT SUM(...
jvkloc's user avatar
  • 133
0 votes
1 answer
39 views

Is UPDATE FROM still not in the ANSI standard?

This article fascinated me it claims that FROM clauses in UPDATE are not part of the ANSI standard. Unfortunately, it is very old and I don't care to buy a copy of the latest ANSI standard for SQL. Is ...
J. Mini's user avatar
  • 137
-2 votes
1 answer
105 views

Oracle SQL - Selecting First Row for each ID

I am using Oracle SQL Developer and I am trying to pick the first entry of the student population. So, that I have one row for each ID. ID DEGREE AWARDED ACADEMIC PERIOD 147 GR MS 2022 147 UG BS ...
DataAnalyst's user avatar
0 votes
2 answers
171 views

Comparing 2 count columns with case

I have 2 tables, size and cost. My query does a count with a greater than comparison of cost and counts different sizes. table1: size u table2: cred t Here is my query: select u.size as size ,...
tkmagnet's user avatar
-1 votes
2 answers
1k views

SQL Cursor vs WHILE loop

When you need to loop a set of data, is there a benefit of using a SQL Server cursor. Or is using a WHILE loop (see below) just the same. I ask because the WHILE loop seems clearer and easier to ...
Craig's user avatar
  • 503
0 votes
1 answer
107 views

MySQL - Fuzzy Match Text on Each Side of Newlines

I am working on an issue where I need to check a street field or exact matches at a minimum but also, if at all possible, fuzzy matches. For example, if I have address 1234 Some Road, it should at ...
Marisa's user avatar
  • 23
3 votes
1 answer
235 views

Why do conditionals apply to SET NOEXEC ON but not SET NOEXEC OFF?

Of the four select statements in the following script, I would expect the second and third statements to execute and the first and fourth not to execute. The first does not, but the fourth does. It ...
Todd Ropog's user avatar
1 vote
1 answer
168 views

MySQL 1054 Error After Creating Trigger to Update on Insert

I am learning basic SQL and have gotten stuck with triggers. I have a database with two tables, customer and invoice. The table characteristics follow: CREATE TABLE customer ( CUST_NUM ...
Kegan Smith's user avatar
2 votes
2 answers
52 views

Backup syntax error with constructed string

This is doing my head in. What am I missing? Syntax errors with '+' and ; -- Step 1: Perform a database backup BACKUP DATABASE iMIS_Prod TO DISK = 'G:\SP_Backup_Daily\iMIS_Prod_' + ...
Clyde Hunter's user avatar
0 votes
2 answers
488 views

Select using multiple lists from top to bottom

I need to select a value (Id) from a table based on matching items in 2 lists. Example. List 1 = ('Tony','Adam','Mark') List 2 = ('Everton', 'Arsenal', 'Villa') Table Id,Number, Name, Team 1, 100, ...
Mogsy Mo's user avatar
0 votes
0 answers
111 views

MariaDB: Syntax error in SET variable statement

I have a MariaDB transaction in which for the life of me I cannot see the syntax error: START TRANSACTION; SET @config_name='test'; SET @config_version = (SELECT IFNULL(max(`Version`)+1,0) FROM `DEV`.`...
JRA's user avatar
  • 3
1 vote
1 answer
675 views

Using COUNT returns the same value when counting two different columns

I am new to SQL and am using it for a school project and would like some help. I have a table with multiple columns about a fictional company that provides a bike sharing service. One of the rows I am ...
YellingYeti's user avatar
0 votes
1 answer
1k views

Postgresql : merge rows of json key-value into one flat dict (not an array)

In Postgresql, I want to build a flat JSON "dict" out of returned rows of key/values When I call : select json_agg( jsonb_build_object(key, COALESCE(value,'')) ) from props; I get spurious ...
MoonCactus's user avatar
5 votes
1 answer
117 views

What are these single letter SQL keywords?

I am looking at list of SQL keywords here https://www.postgresql.org/docs/current/sql-keywords-appendix.html There are some single letter keywords there. I cannot find any information about them. ...
Pratik Deoghare's user avatar
3 votes
3 answers
7k views

"ERROR: column "a" does not exist" when referencing column alias

I am attempting to retrieve either a null or boolean value from a query. Here is my query: SELECT EXISTS (SELECT 1 FROM employee where add_uuid = '7e53fa47-ade3-4e94-8efd-b25f998b09c6') ...
Aamir's user avatar
  • 133
3 votes
1 answer
329 views

Error Sql (1064) creating a function in MariaDB

I am getting an error in MariaDB when trying to create a function. It gives me the following error and I leave the script below. The script: CREATE PROCEDURE `total_hh`(fechainicio datetime, ...
Eduardo Estay Atenas's user avatar
1 vote
1 answer
215 views

Need to query MySQL data without knowing exact schema name

I have an issue where the MySQL schema contains more than one active schema and when I go to query a set of tables, I get the error that I need to select the schema. I know I can just find the name ...
z0rg's user avatar
  • 11
6 votes
3 answers
879 views

Why are unquoted identifiers upper-cased per SQL-92?

Section 5.6 of the SQL-92 standard contains rules 10...13 per which unquoted identifiers should be upper-cased, so foo becomes FOO but "foo" remains foo. These rules are respected by Oracle, ...
Sergei Morozov's user avatar
1 vote
1 answer
699 views

Why does a Postgres recursive CTE need the list of columns as argument?

This is kind of a subjective question. If I have a recursive CTE something like: WITH RECURSIVE r(x, y) AS ( ... SELECT x, y -- select1 FROM t WHERE .. UNION SELECT t.x, t.y -- ...
ahron's user avatar
  • 793
0 votes
1 answer
74 views

Using whole row in Row Level Security policy

I am using row level security with function, for example CREATE POLICY person_select_policy ON core.person FOR SELECT USING (core.person_policy_check(id, 'read') = TRUE); Is it possible to pass whole ...
YangombiUmpakati's user avatar
0 votes
3 answers
2k views

Select rows where date exist in list. If not found, get next closest date

I have been trying to get records from a table by providing a list of dates. But some dates from that list doesn't exist in my table, so in that case I want to get the next closest date. I used this ...
1024 KB's user avatar
1 vote
1 answer
29 views

Syntax issues when uploading backup from mysql5.7 to percona xtradb 5.7

Greetings to those readying the thread and thank you for devoting your time to answering the question. I have encountered a problem when uploading a MySQL 5.7 backup database to a Percona xtradb 5.7 ...
michael peychev's user avatar
0 votes
1 answer
1k views

Sqlite fails when performing an 'insert' with a 'returning' value clause

I am having problems with SQLite? I didn't have this problem when using the same tables on PostgreSQL. When the table is empty and you use the following SQL statement it throws an error. INSERT INTO ...
Grymjack's user avatar
  • 103
4 votes
1 answer
346 views

Is this valid SQL Server Update syntax?

Today I was reading some of my database notes that were taken long time ago. And I saw this query: UPDATE Sales.Orders SET (shipcountry, shipregion, shipcity)= (SELECT country, region, city FROM Sales....
Fajela Tajkiya's user avatar
0 votes
0 answers
56 views

Writing SQL with selected value as title and calculated sub-total

I need help writing my SQL query. I've got 3 tables. Here's a simplified example. Items Name Description First desc 1 Second desc 2 Item Detail Name Supplier Reorder Level First Amazon 1 Second ...
Dawoodjee's user avatar
  • 498
5 votes
1 answer
553 views

Use square brackets on extended events filter

I want create an extended events session and use the like_i_sql_unicode_string operator to filter the phrase [demo], with the square brackets. I've started with: CREATE EVENT SESSION [demo] ON SERVER ...
Jorge Bugal's user avatar
0 votes
1 answer
26 views

Better ways of concating the value of columns

I have a table with below structure and sample data: create table CUSTOMER_TEST ( customer_num Number, rel_one Number, rel_two Number, rel_three Number, rel_four Number ) ...
Pantea's user avatar
  • 1,412
1 vote
1 answer
5k views

Syntax error in a simple SQL query [closed]

I am using pgAdmin to write a simple SQL INNER JOIN query. However, when I run the code it only will run the first line and give me a syntax error shown below. But, I can select the whole code and it ...
Jennifer Dixon's user avatar
3 votes
2 answers
4k views

Can I write a FULL OUTER JOIN without OR IS NULL?

Here's some data to play with: CREATE TABLE a ( a_id int NOT NULL, a_prop text NOT NULL ); CREATE TABLE b ( b_id int NOT NULL, b_prop text NOT NULL ); INSERT INTO a VALUES (1, '...
AndreKR's user avatar
  • 577
1 vote
3 answers
2k views

MySQL dump import into MariaDB syntax error to use near '*/'

This is the result from mysqldump 10.13 and MySQL 8.0.28 Server. /*!50503 SET character_set_client = utf8mb4 */; CREATE TABLE `user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` int(11) DEFAULT ...
Aley's user avatar
  • 141
0 votes
0 answers
674 views

Syntax error in different version of Postgres

Following statement insert into abc.ad_campaign as ac (client_id, acquisio_id, name) values (356619, 5356522, 'Massage - Hand & Stone') ON CONFLICT(client_id, acquisio_id) DO UPDATE SET name = ...
amanullah's user avatar
1 vote
1 answer
3k views

Trigger uses a procedure or a function?

PostgreSQL version 10 and before use the term "Trigger Procedure" (https://www.postgresql.org/docs/10/plpgsql-trigger.html). But later versions use the term "Trigger Function". ...
Suwanto Raharjo's user avatar
1 vote
0 answers
19 views

Postgresql -- join syntax 'bug' that actually ran [duplicate]

I noticed I wrote a query like this, the day after I wrote it: SELECT T1.col1, T2.col1, T3.col1 FROM our_schema.table1 T1 INNER JOIN our_schema.table2 T2 LEFT JOIN our_schema.table3 T3 ON (T2....
JosephDoggie's user avatar
1 vote
0 answers
302 views

Scalar function parses and runs in SSMS, incorrect syntax in ScriptDOM

I'm preparing the Database migration from compatibility level 140 (SQL Server 2017) to level 150 (SQL Server 2019). As part of the preparation, Data Migration Assistant (DMA) has been run and it found ...
Zikato's user avatar
  • 4,418
1 vote
1 answer
1k views

Query to find data where value of data changed to 0

I am trying to write a query to find the rows where value of particular column changes to 0 from some other value say 1 or above. The value may change from 0 to other value again. But we need data for ...
Rathore's user avatar
  • 19
0 votes
1 answer
57 views

Mongo DB Query does not give desired result

I have two collections in mongo db. One called list with keys id and movieid in it. One called movies with movieid and Genre in it. The results I am trying to retrieve are: Which listid has the ...
abc's user avatar
  • 1
1 vote
1 answer
323 views

MySQL Row Constructor forms in INSERT VALUES vs. VALUES

In MySQL 8, based on my reading of the documentation, INSERT VALUES accepts row constructors in the form: INSERT ... VALUES(1,2,3), (4,5,6), (7,8,9); or INSERT ... VALUES ROW(1,2,3), ROW(4,5,6), ROW(...
Dennis Williamson's user avatar
1 vote
1 answer
19k views

ERROR: syntax error at or near "END" [closed]

I am trying to play around with trigger and found some samples online which I pretty much copied before except changed table name and row counts. But somehow I kept on getting syntax error and ...
Dora's user avatar
  • 125
2 votes
1 answer
4k views

dbeaver check sql for syntax without running

Using the dbeaver tool, I want to check a script for syntax errors without actually running it. Purpose: For a long insert query (postgresql syntax, PostgreSQL 10.15) in the form of: INSERT INTO ...
JosephDoggie's user avatar
-1 votes
1 answer
967 views

how do I filter my data from one column based on another?

I need to filter the sum(f.film_id) as films made to be based on the actor who made them or the actor_id. however I'm having a hard time figuring out the syntax for said query. select concat(a....
Aventrix's user avatar
0 votes
1 answer
26 views

Migration db (error when alter DB)

i am new as DBA. i want to migrate db, can i do one time alter for all data ?. or must one alter to one data ? this my query. DECLARE @name VARCHAR(50) DECLARE db_cursor CURSOR FOR SELECT name FROM ...
jubey simanjuntak's user avatar
0 votes
1 answer
9k views

An expression of non-boolean type specified in a context where a condition is expected, near 'AND' [closed]

ALTER PROCEDURE [dbo].[usp_BaseScan_CycleCount_Report] @StartDate varchar(10), @EndDate varchar(10) AS BEGIN IF @StartDate AND @EndDate IS NOT NULL SELECT * FROM dbo....
pdart237's user avatar
1 vote
1 answer
3k views

Using parameters in stored procedure with plpgsql

I am trying to return the count of overlapping polygons. The problem is that it complains about my "$1" signs: Error is "SQL state: 42601", syntax error at "$1". Why ...
Teh Swish's user avatar
-1 votes
2 answers
472 views

How to get a column from a table that corresponds to another table [closed]

I have these tables: OrderDetails: Orders: Employees: Products: Customers: I want to write a query where I can get the last name of the employee with the largest order quantity. I managed to ...
Onur-Andros Ozbek's user avatar

1
2 3 4 5 6