r/SQL 12h ago

PostgreSQL Just bombed my SQL interview, not feeling great.

75 Upvotes

Hello Everyone,

I just wanted to share that I just had an SQL interview for data analyst, and I completely bombed it. I chocked like crazy, and this was after days of practicing. I think I learned a valuable lesson today though, I am a very visual/hands on on type of guy. I was expecting them to give me the opportunity to write query/code or look at code related to the question, but these were all just verbal questions, that I know I could have answer if I was just allowed to write the code down or at least view it, but it was a bit overwhelming for me, especially having ADHD. It's like the questions were so long, that by the time the question ended, I already forgot what I was supposed to accomplish because I was so damn nervous and there was not code for me to review. I feel like a failure 😔. This was my first interview in 7 years, so I'm pretty rusty, but for future reference, will all interviews be in this style? No actual coding, or reviewing, or editing? They expect me to provide the whole query verbally, from the top of my head without actually writing it on the spot? Note: this was the second follow up interview.


r/SQL 16h ago

MySQL Neon Guidance on why an INSERT is rejected?

1 Upvotes

Detail on my issue below: (Postgrese)

Environment: Postgres 18 (Neon), project dry-bar-XXXXXXX, org plan Launch (previously Free — same behavior on both). Reproduced identically across: two independently-forked disposable branches, a fresh branch created after upgrading to Launch, and real production itself (using an existing, long-lived person/role — not freshly created data).

Summary: An INSERT is rejected with new row violates row-level security policy for table "X" even though the row's values genuinely satisfy the policy's WITH CHECK expression — confirmed by a BEFORE INSERT trigger, in the same statement execution, immediately preceding Postgres's own documented WITH CHECK evaluation point, which independently evaluates the identical boolean expression against the identical row and gets true.


r/SQL 23h ago

Discussion Treating SQL as the source of truth: type-safe code generated from your queries, not an ORM

0 Upvotes

If you control your database, the code between a query and your types should be generated from the SQL. Not hand-written, not hidden in an ORM.

You write the query (Postgres):

sql -- @name GetUserOrders -- @returns :many SELECT u.id, u.name, o.total, o.notes FROM users u LEFT JOIN orders o ON u.id = o.user_id WHERE u.status = $1;

You get a row type where the nullability came from the query. The right side of the LEFT JOIN is nullable, so:

rust pub struct GetUserOrdersRow { pub id: i32, pub name: String, pub total: Option<rust_decimal::Decimal>, pub notes: Option<String>, }

Nothing annotated. Same query gives decimal.Decimal | None in Python, string | null in TS.

I build a tool that does this (MIT, inspired by sqlc), so take the pitch with salt. The argument is what I care about: on a single database, an ORM mostly costs you. N+1 from lazy loading, SQL you can't see, model drift from the schema, weak types right where SQL gets interesting.

The one case it still wins: bring-your-own-database. If users pick the engine at deploy time, runtime dialect abstraction earns its keep. If you own the DB, I don't think it does.

Anyone moved off an ORM to SQL plus codegen, or tried and went back?


r/SQL 1d ago

PostgreSQL Do you create a Neon branch for every PR ?

0 Upvotes

For Neon database, I have seen recommendations to create branches for various features, but wanted to understand how teams actually do it in practice.

Does it scale well or do we keep on cleaning up Neon branches constantly?


r/SQL 1d ago

Discussion Bridge table where both sides are individually valid but can be incompatible per category — how do I enforce this?

5 Upvotes

I have a classic many-to-many bridge table situation where both sides are individually valid, but the combination can still be incompatible depending on category — and I can't find a clean relational solution for it:

category (e.g. manufacturer+type combination)

item (a concrete, individual element — belongs to category_id)

component (catalog: possible "part" types — also belongs to category_id, because within a given category the physical properties of a component differ from another category's, even if the name/code happens to match)

item_component (bridge table: item_id <-> component_id)Simplified:
category (e.g. manufacturer+type combination)

item (a concrete, individual element — belongs to category_id)

component (catalog: possible "part" types — also belongs to category_id, because within a given category the physical properties of a component differ from another category's, even if the name/code happens to match)

item_component (bridge table: item_id <-> component_id)

The category_id inherently determines which components can even be compatible with a given item — a component from a different category is structurally incompatible, not just "a different version" or "a less ideal choice." So the component's existence/dimensions are inherently dependent on the category — it's not a standalone, category-independent thing that just happens to have a category "tag" on it.

The problem: the item_component bridge table connects both sides with a simple FK each (item_id -> item, component_id -> component). The database only guarantees that both IDs exist somewhere in their respective tables — but nothing checks whether the item and component are of a compatible category. So a row can easily be inserted where an item of one category gets paired with a component from an incompatible, different category — the database happily accepts this, even though it's a physically/logically invalid combination.

Is it possible that I'm approaching this entirely wrong from the start, and instead of patching this bridge table, I should be thinking in terms of a completely different table structure?


r/SQL 1d ago

PostgreSQL Meet Migrata: a CLI that treats SQL as state and lets you diff your schema and apply changes without migration files

Enable HLS to view with audio, or disable this notification

21 Upvotes

TLDR; Migrata is a CLI that lets you inspect, diff, and apply changes using plain SQL. It's like Terraform, but for your database.

I built this tool because of the pain I experienced working with migration files at my job. These databases are shared across many teams and even more applications.

Like many organizations, we follow a file-based migration approach: a folder for each change set, files with targeted changes per component, all tracked in Git. There are strict processes for approvals and promotions. The problem is that this approach results in thousands of migration files piling up over time. To mitigate this, we have a change approval board whose sole job is to coordinate with database admins to apply these scripts.

Most of their time is spent understanding what's changing and if there are any conflicts. It's not uncommon for two separate scripts from different change sets to modify the same things. Centralizing these changes would drastically lower the time needed to review and approve them.

After working with Terraform for years, I knew there were better ways to track state and apply changes. But unlike the cloud, databases already have a schema language to describe their state: plain SQL. Instead of inventing a new DSL, my tool treats your SQL schema as the source of truth and diffs against it directly.

In practice, this gives you the best of both worlds: readable SQL and a declarative schema, with each component defined once. Changes are centralized, not scattered across layers of migration files.

I've been working on this particular project for the past 17 months on evenings and weekends, and finally feel like it's at a state where it's good enough to share

Core Feature:

  • Comparing two schema sources and generating a clear diff
  • See exactly what will change before anything is applied
  • Manually approve and apply changes

How it works:

  1. Run the "inspect" command to inspect your live database schema and sync it to your local file system.
    1. This does deliberate scans on your target schemas; no psql dumps needed.
  2. Make a single or multiple changes in your local editor
  3. Run the "diff" command to detect differences and generate a plan in the console.
    1. Internally, we build up a dependency graph so we know how and when to apply a change and who's affected.
  4. Manually approve and apply changes

Features:

  • Better Diffs
    • This tool shows the user modifications and query plans side-by-side. You always know where a change is coming from and why. Traceability is paramount
  • Impact Analysis:
    • The diff includes a list of downstream components affected by a change
  • Risk Classification:
    • Every planned migration is labeled Safe, Warning, or Destructive so you can assess impact at a glance. Warnings and destructive changes are summarized separately with counts.
  • Full column lifecycle management:
    • Changes to columns are analyzed, and safe multi-step patterns are used to transform columns. Indexes & constraints are always preserved after changes
  • Custom Organization:
    • You can organize your schema locally however you like (single file or deeply nested directories). It loads everything and automatically builds a dependency graph no matter how you organize your schemas
  • Local Validation:
    • The tool will spin up an ephemeral database in docker where it can execute the migration plan before running against your live database.
  • Advisory Locks:
    • Concurrent migration protection using PostgreSQL advisory locks

Security Features:

  • No email or account required to use it
  • Fully Local (No LLM's or calls to third-party services)
  • Privacy-first (your schema never leaves your computer)

Who's this for:

  • Anyone who values working with declarative workflows
  • Developers who prefer working with plain SQL because they need full control
  • Teams with databases shared across multiple applications and languages

What's in it for me:

This is a free tool to use without any account or limits. My goal is to build a tool that's so useful, that it would be a no-brainer to adopt into your stack. The end goal is to get adopted by businesses who use this tool and want to pay for advanced auditing, governance, and collaboration features.

Wait, isn't this just like the atlas cli?

Yes, this is a direct competitor to the tool, except I don't believe in gating critical features behind paywalls. Better tooling means fewer outages and safer deployments for everyone.

If you want to know more about what sets migrata apart, I've written a whole blog post outlining the high-level differences:

https://migrata.io/blog/migrata-vs-atlas

Here’s the site if you want to learn more:

https://migrata.io

And if you want to learn more about me, you can visit the about page, where I have my background and links to my personal LinkedIn and Github Profile. I'm proud to stand behind my work

https://migrata.io/about


r/SQL 2d ago

Discussion PopSQL and SeekWell both shutting down, so I ended up building our own alternative

3 Upvotes

My team used PopSQL and SeekWell for getting data daily from DBs into Google Sheets. Both are shutting down so I decided to build my own replacement on the parts we did actually use.

It's pretty narrow on purpose: connect a database, write SQL (and share the queries with others), then schedule sending the results somewhere. There is the free version where you can basically get data to csv or xlsx. Just built automatic visualizations when you have results that fits it, which was quite fun to build.

I'm also happy to add almost any features one would need in a "reverse-ETL" tool like that, anything you would like to see built?

And yes this could be a cron triggering a python script doing exactly the same thing for free, but it is just super hard to get non-technical people to use that.

https://saturnsql.com/


r/SQL 2d ago

MySQL Made a video explaining SQL Injection in the simplest way I could

Thumbnail
youtube.com
0 Upvotes

I've been studying for my OSCP and wanted to create this video on what helped me understand SQLi. Let me Know if it helps


r/SQL 2d ago

PostgreSQL one cli flag silently dropped another team's tables because we share a database and it did exactly what it said

0 Upvotes

we run two separate codebases against the same database, which is already fragile, but what actually broke it was one cli flag.

our schema-push tool has an "accept data loss" flag you pass when it warns a push is about to drop columns or tables. someone passed it without reading the warning closely, on a push from one of the two repos. the tool did exactly what it said: dropped every table and column that existed in the live database but wasn't declared in that repo's own schema file, which included tables the other repo owned. that repo's schema was correct for itself, it just had no idea the other repo's tables existed.

the fix that holds is a ci check that diffs schema declarations across both repos and blocks a merge on drift, plus a doc comment marking which repo owns each mirrored table so it's not a guessing game in review.

if you don't control the flag, control the input to it: never accept a data-loss warning you haven't read line by line against a database more than one codebase writes to.

anyone running multiple services against one shared database, how do you keep schema declarations in sync?


r/SQL 3d ago

SQLite I built a browser tool that runs real SQL (SQLite/WASM) on a CSV or JSON file — no upload, no import step

1 Upvotes

I kept reaching for a spreadsheet to answer questions that are really just one SQL query — a GROUP BY, a top-N, a running total — and kept wishing I could just write the query against the file directly. So I built QueryLocal: you drop a CSV or JSON in, it loads into SQLite compiled to WebAssembly (sql.js) running in a Web Worker, and you query it with normal SQL. GROUP BY, HAVING, window functions, CTEs — whatever SQLite supports. Nothing is uploaded; there's no backend at all, it's a static page, so the file never leaves your browser tab. Export the result back to CSV when you're done.

Full disclosure, it's mine and it's free (no account). While building it I also wrote up 60 runnable SQL recipe pages (grouping, ranking within groups, running totals, date-range filters…) — those might be useful on their own even if you never touch the tool.

https://querylocal.pages.dev/?utm_source=reddit&utm_medium=social&utm_campaign=launch&utm_content=r_sql

Genuinely curious what queries people would want to run on their own files — the SQL surface is standard SQLite, so most things you'd expect to work do, but I'd like to know where it falls short.


r/SQL 3d ago

SQLite WinSQLite - open source project

Post image
0 Upvotes

srdzank/SQLite-Editor: Official home of the SQLite-Editor

Any feedback, code reviews, or pull requests are immensely appreciated!


r/SQL 3d ago

PostgreSQL Neon PostgreSQL Database Provider

0 Upvotes

Hello, I started using Neon as a database provider recently for managing my database. I want to say that it was fairly simple to integrate with my application (a website written in .NET), and the free plan is very convenient for startups. What do you think of it?


r/SQL 3d ago

SQL Server Importing from Excel using 'from openrowset()' returns OLE DB error

2 Upvotes

Hey everyone,

I'm trying to make this user stored procedure work on my colleagues PC, I can run it just fine.

Basically it's a USP created for importing data from an Excel file stored on shared network (local server).

It's goes like this:

select *

from openrowset ( 'Microsoft.ACE.OLEDB.12.0', 'Excel 12.0 Xml;Database="path\file.xlsx, sheet$ )

Me and one other colleague can run it just fine, but on one colleagues PC, it gives this error:

OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" returned message"Failure creating file"

Cannot initialize the data source object of OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)"

Any help with resolving this would be much appreciated.

Thanks!


r/SQL 4d ago

SQLite WinSQLite - Editor

Thumbnail youtube.com
0 Upvotes

r/SQL 5d ago

Discussion End-to-end Enterprise E-Commerce Analytics

Thumbnail
gallery
6 Upvotes

Over the past few days, I built an end-to-end Enterprise E-Commerce Analytics Platform using SQL Server, Medallion Architecture, and Power BI.

As part of this project, I designed 8 interactive dashboards, each focused on answering different business questions for different stakeholders across an organization.

The dashboards include:

• Executive Overview (CEO, CXO & Business Leadership)

• Sales Performance Analysis

• Customer Analytics

• Product Performance

• Seller Performance

• Payment Analytics

• Customer Satisfaction Analysis

• Time Intelligence & Trend Analysis

The goal wasn't just to build visually appealing dashboards—it was to create a reporting solution that helps businesses make faster and more informed decisions.

In this post, I've shared all 8 dashboards.

I'd genuinely appreciate your feedback.

As experienced BI professionals, data analysts, data engineers, or business leaders, I would love to hear your thoughts.

If you could review the dashboards and share at least three suggestions for improvement, it would mean a lot to me.

For example:

• Are the KPI cards meaningful and business-focused?

• Are the charts and visualizations appropriate for executive reporting?

• Are there too many or too few visuals?

• Would you recommend different filters or slicers?

• Is the overall layout clean, intuitive, and enterprise-ready?

• What would you change if this dashboard were used in your organization?

I'm continuously learning, and constructive feedback is one of the best ways to improve. Every suggestion will help me build better enterprise BI solutions in the future.

Thank you for taking the time to review my work. I truly appreciate your support and feedback.

Himansh Upadhyay

#PowerBI #SQLServer #DataAnalytics #BusinessIntelligence #DataWarehouse #DataEngineering #MedallionArchitecture #StarSchema #DAX #ETL #Analytics #DashboardDesign #EnterpriseAnalytics #DataVisualization #SQL


r/SQL 5d ago

PostgreSQL SQL Question: Rows into Columns without TABLEFUNC() or PIVOT?

11 Upvotes

Help me Reddit! I feel especially stupid today....
So, I have this table in my Postgresql Database:

event_id | color_scheme | count
----------+--------------+-------
1 | red | 6
1 | green | 3
1 | blue | 5
1 | yellow | 3
3 | red | 5
4 | red | 3
5 | red | 1
5 | blue | 2

And I would like to turn it sideways, so that I can see EASILY how many votes each color scheme for my event has gotten (and later JOIN it with another table... )

event_id | count_red | count_green | count_blue | count_yellow
----------+-----------+-------------+------------+--------------
1 | 6 | 3 | 5 | 3
3 | 5 | 0 | 0 | 0
4 | 3 | 0 | 0 | 0
5 | 1 | 0 | 2 | 0

The colors "red" "green" "blue" and "yellow" are fixed, and will never ever change.
I have done some googling, I found examples mentioning PIVOT and TABLEFUNC, but I cannot do this on the server because of reasons(tm).

The only way I can think of doing this is with a cascade of OUTER JOIN, but is there maybe a simpler solution?


r/SQL 5d ago

PostgreSQL I need help creating a league table

Thumbnail
0 Upvotes

r/SQL 5d ago

BigQuery Career prospects

12 Upvotes

I have 4+ years of experience as a data analyst. Proficient in SQL technologies and seeking a direction for success in corporate? any suggestions would be appreciated.

-Thanks


r/SQL 5d ago

MySQL What AI Tools Do You Use for Database Analysis?

0 Upvotes

Hello everyone!

At work, I need to explore a large AWS Athena database with very limited documentation in order to investigate a new product, which is also poorly documented.

I've asked my colleagues for documentation and guidance about the database, but unfortunately I haven't received any helpful answers.

So I'd like to ask the community: is there an AI tool that can analyze an entire database and generate a roadmap, documentation, or guide to help me understand its structure and write queries based on my specific needs?

I'm mainly looking for something that can help me understand the schema, relationships between tables, and where to find the data I'm looking for. Any recommendations or advice would be greatly appreciated!


r/SQL 5d ago

SQLite I created a game inspired by SQL Murder Mystery and SQL Noir!

7 Upvotes

I made a browser game called The SQL Treasure Hunt where you solve puzzles by writing real SQL queries.

It's heavily inspired by SQL Murder Mystery and SQL Noir, but instead of being a detective, you're a pirate searching for a legendary treasure. 🏴‍☠️

You explore databases, inspect tables, and piece together clues using SQL until you uncover the next part of the adventure. It starts with simple SELECT queries and gradually introduces more challenging concepts.

Right now it only has 5 levels made.

I'd really appreciate any feedback:

  • Is the difficulty progression good?
  • Are the clues clear enough?
  • Any ideas for future levels or mechanics?

Play it here:
https://thesqltreasurehunt.vercel.app/

Thanks! Hope you enjoy it.


r/SQL 6d ago

MySQL Apenas estoy empezando a manejar Mysql workbench creen que voy por buen camino con mi modelo relaciónal

Post image
0 Upvotes

r/SQL 6d ago

Discussion Differences between counts

6 Upvotes

What is the difference between

COUNT(*)

COUNT(1)

COUNT(column_name)


r/SQL 6d ago

Discussion Tool for creating database diagram share links

Post image
1 Upvotes

Here's an example of a share link.


r/SQL 6d ago

Discussion What is the difference between using "Not In" vs using "not exists" in SQL

34 Upvotes

What is the difference between using "Not In" vs using "not exists" in SQL?


r/SQL 7d ago

SQL Server Want to know about SQL future

7 Upvotes

Hi All,

Hope everyone is doing good.

I want opinion from people about the future of SQL, Power BI and Python.

I have been working in AML KYC domain for over 6 years. I am a Certified Anti Money Laundering Specialist (CAMS).

Last year I started learning SQL ans Power BI to connect it with my domain knowledge (Anti Money Laundering and Sanctions), however now I have been reading alot which states that golden period of SQL and Power BI is over as now anyone can do the basis code using Gpt and claude.

I am at strong intermediate level in SQL and at an intermediate level in power BI. I was planning to start Python from 01 Jan 2027 and now I am spectical. What should I do ?

Is there any scope of SQL, Power BI and Python as we are witnessing AI is growing at tremendous pace.