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
2
votes
1answer
44 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
14 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
42 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
15 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
30 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
10 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
42 views

Returning only 1 row that meets some criteria

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
17 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
20 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
23 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
110 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
28 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
19 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; ?...
0
votes
0answers
44 views

QueryParenthesisExpression, is it the correct syntax, or old syntax?

Is there a difference between using Insert tableName (ColumnName) Select ColumnName From Table and Insert tableName (ColumnName) (Select ColumnName From Table) I found it in some cases, and didn'...
5
votes
2answers
472 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
448 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
311 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?
0
votes
1answer
39 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
0answers
21 views

Syntax highlighting in View Designer and Edit All Rows

I simply want syntax highlighting for the View Designer and Edit All Rows For example, in the View Designer SQL (right click View >> Design) And in the Edit All Rows SQL (right click Table >> Edit ...
0
votes
1answer
29 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
302 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
26 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
vote
1answer
298 views

Getting Nested query result from Cosmos DB with property named “Value”

I have Cosmos Db collection, I am trying to query the "Key" "Value" pair from. Working query: SELECT ed From c JOIN ed IN c.ExtendedData Where ed.Key = "MembershipTypeId" And got result: [ { ...
-2
votes
1answer
42 views

ON DELETE / ON UPDATE doubts

I was looking at database past exam from the school that I attend, and I have a question about ON DELETE and ON UPDATE. The question in the past exam was: Show the contents of the tables after ...
1
vote
1answer
645 views

MySQL load data infile ERROR 1064

I am using MySQL version 5.5 and I am trying to use load data infile and I am getting errors. I've looked at the documentation and it looks like I am doing exactly what the docs specify. Running ...
1
vote
0answers
37 views

Syntax error while using variables in stored procedure

This might look like a silly question so pardon me. I was trying to write a trigger in mysql and am constantly getting #1064 which, I believe is a syntax error. Here is the sql for the trigger: ...
0
votes
1answer
33 views

What is the default column name given to a TABLE() type with a single column

CREATE OR REPLACE TYPE MISSING_KEYS AS TABLE OF VARCHAR2(256); SELECT [¿what goes here?] as missing_key FROM TABLE (MISSING_KEYS('A','B','C','D')) What is the default column name that should be in [¿...
0
votes
2answers
48 views

Is it possible to refer to alias before it is assigned? [duplicate]

Does the query shown below work? (Sorry for this type of question, but I am a novice and it is not possible for me to run it right now). SELECT table.id SUM(10/ta.value) AS amount JOIN tableA ...
3
votes
1answer
810 views

Incorrect syntax near '+' in stored procedure sql server

I am writing a stored procedure which will accept a parameter and send mail to some recipients. I am using the sql builtin stored procedure. here is the code create proc send_mail_admin(@usage_data ...
0
votes
0answers
20 views

Is it possible to create an SQL transaction that rollbacks on syntax errors?

In may day-to-day job, I often have to create SQL files containing minor changes (no DDL operation usually) in order to migrate those to production databases easily. The problem is, even with syntax ...
0
votes
1answer
68 views

Set the file name in “SELECT … INTO DUMPFILE”

I am trying to write a query to dump a single LONGBLOB data into a file. SELECT data FROM table WHERE id = 123 INTO DUMPFILE fileName which data, fileName, and id are the fields in the table. SQL ...
2
votes
0answers
43 views

Relational Algebra: how to express the combination of aggregation and projection?

Here I have a table, I would like to query the average salary of departments, the SQL statement should be select dept_name, avg(salary) from employee I try to express this SQL in relational algebra....
2
votes
1answer
45 views

Does the ANSI SQL Standard allow filters or parameters in JOIN conditions?

Does the ANSI Standard find the following SQL sinppet syntactically correct? I am interested specifically in the last line: SELECT name, dept_name FROM employee JOIN department ON employee....
0
votes
2answers
328 views

Postgresql, commas in string_agg function [closed]

Need FIELD like this, with ' and without , at the end of whole field. {name:'color',value:'red'},{name:'width',value:'300 ml'} Tried string_agg(distinct '{name:\'' || param_name || '\',value:\'' ||...
1
vote
1answer
1k views

max_stack_depth error in postgresql

I am fairly new to PostgreSQL and would appreciate any help and recommendations. I'm running the following function to update a table: $BODY$ DECLARE commercial_period date := (SELECT periods....
0
votes
1answer
50 views

Query to get the physical file name of the database

Im trying to get the physical file name of a database, and when i query sys.database_files, under the physical file name column, you get the whole path (ie. S:\Program Files\Microsoft SQL Server\...
0
votes
1answer
65 views

Syntax error in simple trigger

I have a SQLite table with these fields among others Fld_QuoteNumberRoot string Fld_Revision integer Fld_QuoteNumber string I need to fill ...
5
votes
1answer
258 views

Can’t run a function against EXEC

My SQL Server book says you can't run a function inside EXEC and shows an example: DECLARE @NumberOfLetters int = 15; EXEC(‘SELECT LEFT(Name,’ + CAST(@NumberOfLetters AS varchar) + ‘) AS ShortName ...
11
votes
1answer
860 views

Can we put an equal sign (=) after aggregate functions in Transact-SQL?

I have encountered a script like this: set @sum = sum = (case when somecol1 is null then DATEDIFF(d,[somecol2],somecol3) else 0 end) I can't understand the meaning of the equal sign (=) after the ...
-2
votes
1answer
45 views

Query syntax error [closed]

I tried a lot but can't find what is wrong with this query, It gave me this error: Incorrect syntax near ')' WITH cte AS ( SELECT * FROM ( ...
1
vote
1answer
71 views

What are some consequences of putting quotes in a WHERE clause for an integer column?

I have a table with a column some_column of data type integer. I've noticed that my PostgreSQL 10.6 instance is smart enough to interpret both of the queries below as same: select * from my_table ...
-1
votes
1answer
410 views

MySQL: Syntax error around foreign key assignment [closed]

I put the following into DB Fiddle in an attempt to debug it. The error is below Results Schema Error: Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds ...
0
votes
1answer
147 views

Select query with nested relationships

I have the following 3 PostgreSQL tables: wallet: +----+--------+-----------+-----------+--------+ | id | name | createdAt | updatedAt | locked | +----+--------+-----------+-----------+--------+ | ...
1
vote
1answer
118 views

Can DBA create a public synonym for a table that has the same name as an existing table

Suppose a DBA created a public synonym for a table and named it hr. The user also created a table with the same name hr. If a user performs a query like the following statement: select * from hr; ...
1
vote
0answers
35 views

Escape from Alcatraz: SqlAnywhere to MSSQL [closed]

Is there a migration tool that actually works for SAP SqlAnywhere 17 to MSSQL (any recent version)? Searching for "sqlanywhere mssql migration" yields a variety of hits including SQL Server ...
1
vote
1answer
402 views

Postgres 10.0 upsert syntax error not sure what to google for

Postgres 10.0 table: pcr=> \d tableFindOld Table "public.tablefindold" Column | Type | Collation | Nullable | Default ----------+--...
0
votes
1answer
69 views

Missing data in SQL Server

I need to find the data that is present in Oracle, but missing from SQL Server. I have tried the below query, but am getting the following error: The multi-part identifier "PS.TXN_ID" could not be ...
1
vote
1answer
3k views

Syntax error when trying to add columns to table in DBeaver (postgresql)

I've tried this a few different ways but every time I get a syntax error when trying to add columns to a table. I'm new to databases so it's probably something basic that I'm doing wrong, but I just ...
6
votes
1answer
617 views

Unfamiliar syntax - Query with Parameters in Braces at the beggining

I have run sp_WhoIsActive on one of our servers using the following syntax: sp_whoisactive @get_plans = 1, @show_sleeping_spids = 0, @get_outer_command = 1, @get_locks = 1 and found a spid with the ...
0
votes
1answer
582 views

MySQL syntax error 1064 near IN stored procedure

an aspiring DBA Here. I'm trying to create a stored procedure for a query I'm running. It is a memsql server which is MySQL based. The procedure is as such: delimiter // CREATE PROCEDURE ...

1
2 3 4 5