News for hackers. Stuff that matters.
Re:Type Constraints in 65 lines of SQL by weird-eye-issue on Friday February 17, 2023 @12:55PM (#34837968)
Way easier handling this in the application code. If I had a developer join my team then commit this into the codebase rather than just using the ORM that everyone else is familiar with they would be fired UNLESS there was a very good reason for doing so
Re:Type Constraints in 65 lines of SQL by ericHosick on Friday February 17, 2023 @01:16PM (#34838248)
> using the ORM that everyone else is familiar with

A relational database isn't always fronted by the same tech. You have RESTful APIs, GraphQL APIs, Low Code/No Code Solutions (like Retool), reporting tools, ETL systems, etc.

You have company mergers where that one familiar ORM is now five to six unfamiliar ORMs.

Ensuring data integrity is key and easiest way to do that is to push constraints as close to the persistence layer as possible.

Re:Type Constraints in 65 lines of SQL by thor_molecules on Friday February 17, 2023 @12:59PM (#34838023)
So in this case, you've let a new dev commit to a code base without review.

Then, instead of informing them of best practices and giving them time to re-work the code, you'd just fire them?

Interesting strategy.

Re:Type Constraints in 65 lines of SQL by weird-eye-issue on Friday February 17, 2023 @10:08PM (#34843475)
Creating a pull request requires committing code too.
Re:Type Constraints in 65 lines of SQL by oliverrice on Friday February 17, 2023 @01:01PM (#34838064)
Agreed that there should be a data integrity or custom operation/filter/sorting requirement to motivate a user defined type
Re:Type Constraints in 65 lines of SQL by cgh on Friday February 17, 2023 @05:48PM (#34841690)
Easier, slower, more error-prone. Also, you should consider implementing code reviews rather than just firing people who commit code you don't like.
Re:Type Constraints in 65 lines of SQL by doctor_eval on Friday February 17, 2023 @06:06PM (#34841837)
I love working directly in plpgsql, it makes it possible to perform all the database logic in the database, effectively presenting a domain-specific API to the world. This api is then available to any SQL user. It’s like creating a built in CLI for your data.

Putting logic directly in the database is much faster at runtime, doesn’t require redundant entity definitions, is substantially more likely to detect schema problems, and is way easier to test.

And it removes the dependency on a specific language and toolchain. Your logic is accessible by everyone.

Unfortunately, the tooling around managing this stuff is not great. The language is a bit boring; idiomatic upper case is the first thing I get rid of.

But it’s the best tool for the job. Far from being “way easier” in application code, plpgsql reduces LOC, improves performance and removes dependencies.

If someone on my team ignored all of these benefits, well, I’d explain it to them and show them examples until they “got it”.

Way easier than firing them.

Re:Type Constraints in 65 lines of SQL by icedchai on Friday February 17, 2023 @07:37PM (#34842613)
Very few people know plpgsql. Like all stored proc languages (Oracle PL/SQL, etc.) it looks and feels like something out of the 80's. It's annoying to deploy, annoying to debug, annoying to test. Many developers today barely know SQL.
Re:Type Constraints in 65 lines of SQL by doctor_eval on Friday February 17, 2023 @07:53PM (#34842707)
It’s easy to make it feel more modern (select ffs from stop_using_all_caps). But it’s an ideal DSL for data manipulation.

It’s not particularly annoying to debug - there are logging, and even single step debugging tools available - and it’s so much easier to test than writing unit tests to do the same thing.

I agree it’s painful to deploy, but as I’ve discovered this is a tooling problem; it’s not at all intrinsic to the medium.

It’s certainly possible to create tooling to make it easier, and who knows? Maybe I’ll have something to show HN one day.

> Many developers today barely know SQL.

If true - a very big if - it’s an inditement of the industry and the incentives we use, not a reason to avoid something that makes code faster, safer and smaller.

Objections to using these languages are a lot more about willingness to learn and try new (old) things, than they are about the capabilities of the platform.