Skip to content
Advertisement

Tag: postgresql

SQL: Advantages of an ENUM vs. a one-to-many relationship?

I very rarely see ENUM datatypes used in the wild; a developer almost always just uses a secondary table that looks like this: But the same thing can also be shown using a user-defined type / ENUM: (Example shown using PostgreSQL, but other RDBMS’s have similar syntax) The biggest disadvantage I see to using an ENUM is that it’s more

How to drop multiple tables in PostgreSQL using a wildcard

When working with partitions, there is often a need to delete all partitions at once. However Does not work. (The wildcard is not respected). Is there an elegant (read: easy to remember) way to drop multiple tables in one command with a wildcard? Answer Use a comma separated list: If you realy need a footgun, this one will do it’s

Variable value assignment using RETURNING clause

I try to do this, but it’s a syntax error, what am I doing wrong? my table: Answer You need to use the INTO clause in the RETURNING to set the value being returned into your variable: You also need to specify the data type of your variable; I’m glad to see postgresql supports %TYPE and %ROWTYPE.

Query to group by maximum depth of PostgreSQL Ltree?

I want to query for all products with the name “Shania Twain”, but I want group them only by the tree with the deepest nlevel. Assuming I have a table like the following with the name categories So, for example, The problem lies with the HAVING clause requiring a boolean expression. The clause MAX(nlevel(cat.tree)) will return an integer. How do

PostgreSQL Index Usage Analysis

Is there a tool or method to analyze Postgres, and determine what missing indexes should be created, and which unused indexes should be removed? I have a little experience doing this with the “profiler” tool for SQLServer, but I’m not aware of a similar tool included with Postgres. Answer I like this to find missing indexes: This checks if there

Advertisement