SShortSingh.
Back to feed

PostgreSQL Generated Columns vs Triggers: When to Use Each for Derived Data

0
·2 views

In PostgreSQL, derived column values can be maintained either through generated columns or triggers, and the right choice depends on what data the value needs to access. Generated columns work best when the value depends only on other columns in the same row using immutable functions, as the database enforces correctness and blocks manual overwrites. Triggers are necessary when the derived value requires data from other tables, the current timestamp, or non-immutable functions. Performance testing on PostgreSQL 18 showed that a row-level PL/pgSQL trigger added roughly 72% overhead to bulk inserts compared to a plain table, while a stored generated column added about 16% and a virtual generated column added none. Beyond performance, generated columns also improve schema clarity since their logic is visible directly in the table definition, unlike trigger-maintained columns which appear as ordinary writable columns.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

Developer shares structured workflow for building and releasing open source projects

A software developer has outlined a practical, step-by-step approach to taking coding ideas from concept to publicly released open source projects. The workflow prioritises identifying a real problem before choosing a technology, then progresses through requirements, a minimal working version, testing, and documentation before any release. The developer emphasises that good documentation — including a clear README, CONTRIBUTING, and CHANGELOG files — is as important as the code itself for attracting contributors. Automated testing and descriptive Git commit messages are highlighted as key habits that keep projects maintainable over time. The post argues that publishing code and iterating based on real-world feedback provides learning that tutorials alone cannot replicate.

0
ProgrammingDEV Community ·

Developer Builds Clash of Clans War Outcome Simulator Using Official Game API

A developer discovered the Clash of Clans public API and used it to build a war simulation tool called WarOracle. The tool analyzes a clan's current war data, including player Town Hall levels, heroes, equipment, and past attack history, to estimate how individual attacks might perform. It then runs Monte Carlo simulations across remaining war attacks to produce win, loss, or draw probabilities along with projected star counts and score ranges. For ongoing wars, already-completed attacks are treated as fixed outcomes, with only the remaining attacks being simulated. The backend is built with Spring Boot and Java, while the frontend uses React, and the developer is still evaluating whether the tool offers genuine value to active Clash of Clans players.

0
ProgrammingDEV Community ·

Independent Benchmark Pits TypeSafe's Jev Model Against GPT-4, Claude, and Gemini

A developer has published an independent benchmark evaluating TypeSafe's Jev model against leading large language models including GPT-4, Claude, and Gemini. Unlike conventional LLMs, Jev outputs probabilities for predefined answer choices rather than generating free-form text. The benchmark focused on classification tasks such as spam detection, sentiment analysis, and topic classification. The tests were designed with reproducibility in mind, with full code made available via a public GitHub repository. Jev's probability-based approach is seen as potentially useful for intent routing, safety guardrails, and low-latency classification pipelines in AI systems.

0
ProgrammingDEV Community ·

Why micro frontend contracts matter more than bundler config

A development team building a React-based government events platform adopted Module Federation to allow independent deployments across multiple teams, replacing a monolithic release process that forced everyone to wait on the slowest team. The core challenge they identified was not the bundler setup, which can be configured in hours, but defining and enforcing explicit contracts between the shell and remote modules. Each remote was required to declare its exposed props, emitted events, and shared dependency version ranges, with the shell refusing to mount any remote that fell outside the agreed range. This approach moved failures to load time rather than production, eliminated release-train coordination, and reduced the overall release cycle by roughly 40 percent. The team concluded that splitting frontends by team ownership, keeping shared dependencies minimal, and writing the contract before touching build config are the critical factors for sustainable micro frontend architecture.