From SQL Queries to DynamoDB Requests
Paste a SQL statement above and you get the request params for AWS DynamoDB: a FilterExpression that keeps your WHERE logic, #name and :value placeholders, and typed values with every digit of your numbers. Where DynamoDB works differently from SQL, a note in the output tells you what to do.
How to Convert SQL to DynamoDB
Paste Your SQL
Type or paste the statement, click "Upload" for a .sql or .txt file, or click "Sample" to see a SELECT with a few WHERE conditions. Several statements separated by semicolons are converted one after another.
Example: a SELECT with WHERE and LIMIT
SELECT user_id, username, email
FROM users
WHERE status = 'active'
AND subscription_tier IN ('premium', 'enterprise')
LIMIT 25;Read the DynamoDB Params
The query above becomes a Scan. The WHERE conditions turn into a FilterExpression, the column list into a ProjectionExpression, and every name and value goes through a placeholder. Strings are written as {"S": "active"} and numbers as {"N": "42"}, the format the AWS SDK's low-level client expects. Notice the note: LIMIT 25 was left out on purpose, because DynamoDB would apply it before the filter.
Output for the example
// NOTE: DynamoDB applies Limit before the FilterExpression, so Limit 25 would stop after 25 scanned items, not 25 matches. Limit was not added — take the first 25 items from result.Items in your code.
const params = {
"TableName": "users",
"FilterExpression": "#status = :val0 AND #subscription_tier IN (:val1, :val2)",
"ProjectionExpression": "#user_id, #username, #email",
"ExpressionAttributeNames": {
"#user_id": "user_id",
"#username": "username",
"#email": "email",
"#status": "status",
"#subscription_tier": "subscription_tier"
},
"ExpressionAttributeValues": {
":val0": {
"S": "active"
},
":val1": {
"S": "premium"
},
":val2": {
"S": "enterprise"
}
}
};Adjust It for Your Table
Copy or Download
Copy the code into your Lambda function or Node.js script, or download it as a .js file. To go the other way, try DynamoDB to SQL, or turn the same SQL into a MongoDB query.
Frequently Asked Questions — SQL to DynamoDB
Which SQL statements can I paste?
SELECT becomes a Scan, INSERT a PutItem (or BatchWriteItem in groups of 25 when there are several rows), UPDATE an UpdateItem and DELETE a DeleteItem. You can paste several statements separated by semicolons and each gets its own params block. Comments, quoted names in "double quotes", backticks or [brackets], and strings with '' or -- inside them are read correctly. JOINs, subqueries, GROUP BY, CASE and functions in the column list have no DynamoDB form, so they stop with an error that says why, and a broken query gets an error with the line and column.
How does the WHERE clause turn into a FilterExpression?
Conditions keep SQL's order of operations, so a = 1 OR b = 2 AND c = 3 is read as a = 1 OR (b = 2 AND c = 3), and parentheses are kept. =, <>, !=, <, <=, >, >=, IN, NOT IN, BETWEEN and NOT work as in SQL, and IN lists over 100 values are split, since DynamoDB takes 100 at a time. LIKE 'abc%' becomes begins_with, LIKE '%abc%' becomes contains and a pattern without wildcards an exact match. IS NULL checks that the attribute is missing or holds a NULL value. DynamoDB compares text exactly, upper and lower case included, while MySQL's LIKE usually ignores case. Column names and values always go through #name and :value placeholders, so reserved words like status or name are fine.
What happens to conditions DynamoDB cannot express?
For a SELECT, a condition such as LOWER(name) = 'ann' or LIKE '%.com' can't be written exactly, so it is left out (or replaced with a looser test) and a NOTE line at the top of the output says so. The Scan then returns extra items that you filter in your code, but a left-out condition never makes it miss an item. For UPDATE and DELETE that would be dangerous, because the write could hit an item the SQL would have left alone, so the converter refuses and explains which condition is the problem.
How are values and long numbers written?
Quoted text becomes S, numbers become N, TRUE and FALSE become BOOL, NULL becomes a NULL value and X'414243' becomes binary (B). Numbers are copied as typed, so 8901240544102066246 keeps every digit and 14.50 stays 14.50; DynamoDB holds up to 38 significant digits. A quoted '00501' stays a string. An unquoted 00501 is the number 501 in SQL, so it is written as 501 with a note. Double-quoted values such as "bob" on the right side of a comparison are read as text, the way MySQL does, with a note.
How do UPDATE and DELETE find the item?
UpdateItem and DeleteItem change one item by its primary key, so the WHERE clause needs it as column = value. A column named id or pk becomes the Key (plus sk if you have one); otherwise every plain equality goes into Key and a note asks you to keep only your partition and sort key. The other conditions move into ConditionExpression. An UPDATE also gets attribute_exists on the key, because SQL UPDATE never creates a row while UpdateItem would. UPDATE or DELETE without a WHERE clause is refused, since DynamoDB can't change a whole table in one request.
Why did my LIMIT disappear from the Scan?
DynamoDB applies Limit before the FilterExpression: Limit 25 reads 25 items and then filters them, so you could get fewer than 25 matches or none. When your SELECT has a WHERE clause (or ORDER BY or OFFSET), the converter leaves Limit out and adds a note to take the first rows in your code. A LIMIT on a query without WHERE is kept. ORDER BY and OFFSET are not applied either, because a Scan returns items in no particular order.
Which client does the output use, and is my query uploaded?
The output is JavaScript for the AWS SDK v3 low-level client (DynamoDBClient from @aws-sdk/client-dynamodb), which takes typed values like {"S": "active"}. If you use the DynamoDB Document Client instead, pass plain values without the S/N wrappers. The conversion runs in your browser. The query is not uploaded and nothing is kept: a reload starts with an empty editor.
Related converters: DynamoDB to SQL · MongoDB to DynamoDB · DynamoDB Query Formatter · MongoDB to SQL
Related Tools
SQL to MongoDB
Convert SQL queries to MongoDB query syntax with aggregation pipeline support
MongoDB to SQL
Convert MongoDB queries and aggregation pipelines to equivalent SQL statements
DynamoDB to SQL
Convert AWS DynamoDB query and scan operations to equivalent SQL statements
MongoDB Query Formatter
Format, beautify, and validate MongoDB queries with proper indentation and syntax highlighting
MongoDB to DynamoDB
Convert MongoDB queries to AWS DynamoDB query operations and vice versa
DynamoDB to MongoDB
Convert AWS DynamoDB operations to MongoDB queries with proper operator mapping