Skip to content
Advertisement

Tag: postgresql

Function as parameter to another function in Postgres

Can I create a user defined function in Postgres either through the C-Language Function API or by using pl/pgsql which accepts a callback function as parameter? As far as I see there is no way to do this through the C-Language API since it only accepts sql datatypes and there is no datatype for function. But maybe I’m missing something?

Computed / calculated / virtual / derived columns in PostgreSQL

Does PostgreSQL support computed / calculated columns, like MS SQL Server? I can’t find anything in the docs, but as this feature is included in many other DBMSs I thought I might be missing something. Eg: http://msdn.microsoft.com/en-us/library/ms191250.aspx Answer Up to Postgres 11 generated columns are not supported – as defined in the SQL standard and implemented by some RDBMS including

Extract first numeric part of field

I have a database (Postgres 7.4) field for address Example Data The queries I get all but I don’t want 123 main street I get the results I want My question is how do I just match the numeric part of the address? Answer Returns 1 or more digits from the start of the string. Leave out the anchor ^

How to COUNT duplicate rows?

I want to be able to create a histogram out of a tuple containing two integers values. Here it is the query: For this input: Would be: How can I create a histogram of those values? In other words, how can I count how many times a row has a duplicate? Answer The question leaves room for interpretation. This test

Postgres: Add constraint if it doesn’t already exist

Does Postgres have any way to say ALTER TABLE foo ADD CONSTRAINT bar … which will just ignore the command if the constraint already exists, so that it doesn’t raise an error? Answer This might help, although it may be a bit of a dirty hack: Then call with: Updated: As per Webmut’s answer below suggesting: That’s probably fine in

Advertisement