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
1
vote
1answer
27 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(...
0
votes
1answer
42 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 ...
0
votes
1answer
144 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 ...
-1
votes
1answer
32 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....
0
votes
1answer
22 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 ...
0
votes
1answer
360 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....
1
vote
1answer
54 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 ...
-1
votes
2answers
49 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 ...
0
votes
1answer
19 views

Postgresql script doesn't work as I expect

DO $$ DECLARE companyNrs text[] = ARRAY(SELECT LPAD(companynr::text, 5, '0') FROM s_users); companyNr text; BEGIN FOREACH companyNr IN ARRAY companyNrs LOOP raise notice '...
0
votes
0answers
20 views

What is an equivalent MySQL function to match CRYPT of PostgreSQL?

In PostgreSQL there is a function that can be used to encrypt passwords, like so: crypt('123456', gen_salt('bf')) What would be an equivalent function for MySQL? Background I am amending code that ...
0
votes
1answer
49 views

Error running PostgreSQL query from SQL Server 2016

The below query runs well in SQL Server 2016: select ResellerId, vCompanyName ,x.* from wlt_tblReseller AS main outer apply ( select (count (ipkReportTypeId)) AS "count", vReportTypeName ...
0
votes
1answer
106 views

Replace all column values with other values in the same column according to primary key

I'm querying the following table: id value applicable id1 5 Unknown id1 5 Unknown id1 6 Yes id 2 5 Unknown id 2 5 No id 2 3 Unknown I would like to replace all "Unknowns" in the ...
0
votes
0answers
22 views

What syntax does PostgreSQL require when all identifiers in a query are dynamic? [duplicate]

Example: SELECT $1 FROM $2.$3 WHERE $1 = $4 Result: ERROR: syntax error at or near "$2" Example: SELECT "$1" FROM "$2"."$3" WHERE "$1" = "$4&...
1
vote
1answer
29 views

Is it possible to reduce the duplication in this simple query?

I'm new to SQL and so this is probably a stupid question but can I reduce the duplication in this query? My actual query involves more complex expressions. Right now I'm just doing string ...
-1
votes
1answer
26 views

What does "player != ANY (SELECT player FROM Member)" return?

I have this table and these queries I've run both queries with these results: I'm confused about the line with the WHERE clause in each query. Specifically that ALL and that ANY. I understand what ...
0
votes
1answer
11 views

Counting number of occurrences, how to "group by"

I have the following query, which works as intended. Database is Sybase SQLAnywhere, which follows t-sql syntax for the most part. I'm trying to add a column to COUNT the number of times each "...
0
votes
1answer
34 views

Postgres SQL: INSERT from DELETE

I have a table with id,user_id,timestamp and I'm trying to INSERT into the table, the user_id from a DELETE from table where id=some_number and timestamp. So what I'm trying to achieve looks like: ...
2
votes
1answer
136 views

Inserting date range arrays daterange[]

I'm trying to insert the value of an attribute of a tuple, which would be an array of date ranges, i.e. a daterange[], in a previous tuple accepted the value: {"[2013-05-08,2018-03-22)"} ...
6
votes
1answer
763 views

Syntax shorthand for updating only changed rows in UPSERT

I have a query which upserts into Postgres when a key conflicts only if there are changes to one of the other columns (to avoid unnecessary inserts and returned rows where nothing was actually changed)...
-2
votes
2answers
1k views

MySQL Join two tables with comma separated values

I've got two tables as below: CARLINE option_value option_name tipologia_auto_1 Citycar tipologia_auto_2 Berlina tipologia_auto_3 SUV Hobby_1 football Hobby_2 Basket Datimarketing (is the ...
2
votes
1answer
103 views

how to use the keyword `VALUES` in an `IN` statement?

I am on sql server 2016 select @@version Microsoft SQL Server 2016 (SP2-CU15) (KB4577775) - 13.0.5850.14 (X64) Sep 17 2020 22:12:45 Copyright (c) Microsoft Corporation Enterprise Edition: Core-...
0
votes
1answer
58 views

PSQL cte delete seem have have ambiguity when select same column from delete table

Both these two sql can be execute , the first one delete all , the second one is logic right. the first one with d0 as ( delete from seller_create_request where seller_id in (...
-3
votes
1answer
2k views

What is "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4" for? [closed]

I'm exploring Sakila database. After CREATE TABLE, I saw this syntax. Could any one help to let me know what is this and what it is for? how and when to use it? (I didn't see this in my SQL course) ...
2
votes
1answer
138 views

Why is the ROW keyword needed when constructing a row with one element, but not two?

In PostgreSQL 11, the following expression UPDATE test_table SET ("column_a","column_b") = ('value-a','value-b') WHERE "column_a" = 'value-c' is accepted and performs ...
0
votes
1answer
160 views

"ENUM" is not vallid at his position, expecting ')' [closed]

I'm keeping this error and I'm very new to mySQL so I don't know what is going on. The only way I found to remove this error message is to put ')' before the ENUM and then the message change - "...
0
votes
1answer
22 views

How do I get rid of the duplicate code in this query?

I have this query, which works: SELECT *, ("last done" + "auto time span"::interval) AS "new last done" FROM personal."time tabs" WHERE "reset ...
6
votes
2answers
5k views

Why is "INSERT INTO table;" a syntax error?

I have this: CREATE TABLE people ( id bigserial, timestamp timestamptz DEFAULT now() NOT NULL, PRIMARY KEY (id) ); CREATE TABLE "...
0
votes
1answer
515 views

Getting generic Oracle error message 'missing right parenthesis'

CREATE TABLE IDN_ORG ( ID VARCHAR2(255) NOT NULL, TENANT_ID INTEGER NOT NULL, NAME VARCHAR2(255) NOT NULL, CREATED_TIME TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, LAST_MODIFIED TIMESTAMP ...
0
votes
1answer
32 views

Why are CASE-expressions in the list documenting operator precedence?

In the list here: https://mariadb.com/kb/en/operator-precedence/ case-expressions are put at the same precedence level as BETWEEN, between the NOT operator and the comparison operators. However, case-...
0
votes
2answers
27 views

SQL CASE query prioritization

I'm doing a pokemon sql table and created a new column named capacity_difference to determine the collectability of each pokemon in the table. However, when I want to use CASE query to categorize them,...
2
votes
1answer
128 views

Function accepts only certain passwords in postgreSQL

I have created a function in a postgreSQL(v10.10) database to create new users or update existing ones. As parameters you pass the username, password, role memberships, first name and last name. In my ...
1
vote
0answers
16 views

Why did Codd, et al. prohibit intermediate scalars in SELECT - and how would they have recommended avoiding syntactic repetition?

(I'm asking this because I was reviewing this older question I asked and because I'm currently writing some queries and getting annoyed at how much I need to repeat myself). In ISO-compliant SQL ...
1
vote
1answer
666 views

Are there better alternatives rather than using a "Full outer join" when it is not possible to use a "left or right join"?

I have two tables with below structure : Create table Modern_transaction (Eeffective_date Date, Customer_Num Number, Branch_Code Number, MTrns_type_one Number, ...
0
votes
1answer
16 views

Query with "Logical operator (AND)" that does not return the desired result set

I have a table: create table test_table (customer_num NUMBER, dep_group VARCHAR2(50), dep_type VARCHAR2(50), balance NUMBER) the table has two records: " ...
0
votes
1answer
243 views

Error "ORA-0091:Invalid Character" when executing a PL-SQL statement in Oracle [closed]

I'm new to oracle pl-sql and I'm facing error ORA-0091:Invalid character when executing this query below. But when I comment the Execute Immediate statement and use dbms_output.put_line the result of ...
0
votes
0answers
30 views

MySQL - Year Over Year - Query Syntax

Experts I am working on a query to get Year over Year data comparison from current year to prior year. For example, if current year is Jan 1st - now, I would calc that dynamically in my query but ...
-1
votes
1answer
81 views

Returning only 1 row that meets some criteria [duplicate]

This is an issue that I run into quite frequently, and which I would love to know how to work through. I'm writing a report/query that is simple enough, but when run, returns rows with duplicate ...
0
votes
1answer
28 views

Can't add or update child, Foreign Key Error

I'm kinder new in MySQL. I was trying to insert value in a relational database. I know that i have to insert in parent table before doing it in child table. Assume we have tables named STATE, COUNTRY....
1
vote
1answer
23 views

Move column to another table by reducing?

I'm not very experienced with database so sorry for lacking correct terminology. I have a structure similar to Employee -Id -Location -Name -StoreId Store -Id -Name And I want to simplify/...
-1
votes
1answer
311 views

SUM first consecutive rows only SQL Server

I have the following data: ROW SEGMENT ORDEN LONG 1 39 11 49.00 2 39 10 102.00 5 39 7 104.00 6 39 6 139.00 7 39 5 97.00 11 39 1 ...
1
vote
1answer
1k views

SQL query with "INTO OUTFILE" does not work on MariaDB 10.4 but does on 10.0

I have an SQL query that executes perfectly on MariaDB 10.0.35 but fails with a syntax error on MariaDB 10.4.12. I attempted to contact them, but they told me to check forums and compare the ...
0
votes
2answers
34 views

How do I write a query that inserts values while AND gets values from another table?

I have a table (Tbl2) that needs to be populated with values from another table (Tbl1). Tbl1 has columns: id (uuid), name, address, gender. Tbl2 has columns: id (uuid), org, name, address, gender, ...
2
votes
1answer
23 views

Weird PostgreSQL expression parsing

How is PostgreSQL parsing supposed to work? rivet=# SELECT 1 IS NOT NULL::int + 2 IS NOT NULL::int; int4 ------ 1 (1 row) But rivet=# SELECT 1 IS NOT NULL::int + (2 IS NOT NULL)::int; ?...
6
votes
2answers
484 views

What is the `TABLE example` syntax called?

In PostgreSQL, I've been using syntax like TABLE example1 UNION ALL TABLE example2 which I understand to be equivalent to SELECT * FROM example1 UNION ALL SELECT * FROM example2 But a colleague ...
0
votes
2answers
9k views

Running a query on the results of another query?

I have 2 queries, they both run fine and pull the results I'm looking for. However, I need to be able to run one query from the results of another. This is t-sql/mssql/sybase For example, the ...
0
votes
1answer
3k views

current_timestamp at time zone 'UTC' SQL Server equivalent

What is the equivalent of the Postgres "current_timestamp at time zone 'UTC'" in SQL Server? How do I select the current timestamp in UTC in SQL Server?
1
vote
1answer
191 views

ms-access concat a string with control source

Sorry for this likely noob question but I cannot seem to find the solution. I'm trying to modify an existing field on a report, standard in this field the data is being pulled from the control source ...
0
votes
1answer
31 views

Why can't I create a index using column definition in MySQL?

Consider the following create table syntax CREATE TABLE test1 (f1 int primary key, f2 int, unique key(f2)); I can also write the above as follows CREATE TABLE test1 (f1 int primary key, f2 int ...
0
votes
1answer
1k views

Calculate 12 months rolling / moving average, median, min, max, percentiles, etc. as single query in Postgres

My question has two parts: . Firstly, how to adjust the code below to calculate 12 month moving avg, median etc.? As is, the query will return a list of daily, weekly, monthly or annual values (...
0
votes
1answer
39 views

Inline expansion of inline composite expression

I want something like this: SELECT 1, (CASE WHEN TRUE THEN (2, 3) ELSE (4, 5) END).*; ...hoping to get 1 | 2 | 3. But in PostgreSQL 11 this query throws: ERROR: record type has not been ...

1
2 3 4 5