i’m not really much of an expert when it comes to databases and i was wondering if it’s possible to do something which might be a little weird I’m having a simple table called options which has 3 …
Tag: postgresql
Postgres 10 sql How can I do distinct without all columns
I have this following query that gets the closest cities/town to a certain coordinate that is passed in . It will return a max of 5 records and I only want to do a distinct on city and state . In the …
Include parameters in posgresql assert message
Is there a way to include parameters in PostgreSQL ASSERT messages. Example: do $$ declare c integer; begin c := (select count(*) from pg_database); assert c = 7, ‘not 7!’; assert c …
Postgres Type of Parameter does not match
I am having an odd problem with Postgres (10.5). I have a function, generate_unique_name which takes in three text values. It works fine; however, calling this function seems to be an issue. When I …
Generically identify the rowid causing a constraint conflict in SQLite
I need to identify the row that caused a constraint check to fail after an INSERT OR IGNORE statement. I need this for a tool that generates SQL statements, so I can’t tie this to a specific use case …
Returning multiple result sets from postgres: refcursors, functions or new features?
Premise: An entity has many children and grandchildren (gists, versions and files respectively, in this instance). When it (gist) is requested, we want its children (versions) and grandchildren (files for versions) as well. Here I am really pushing to do as much in SQL as possible, instead of composing severa…
postgresql inner join and left join
I have the following database structure, with postgres 9.5: create table users ( id character varying(255), email character varying(127) ); create table org_users( id character varying(255), …
PostgreSQL Update and return
Let’s say I have a table called t in Postgres: id | group_name | state —————————– 1 | group1 | 0 2 | group1 | 0 3 | group1 | 0 I need to …
SQL: How to group by with two tables?
I have the tables products and history and I need to group by name: products = (id_product, name) history = (id_history, id_product, amount) I tried this SQL query but it isn’t grouped by name: …
postgresql two NOT LIKE clauses returning wrong results
I have a table with 88 codes. I am writing a simple select statement that does not select the codes that start with 10 or 18 select distinct pcl_mun from exemptions.modiv_parcels_2015 where (pcl_mun …