|
Active3 years, 5 months ago
Select Max Serial Key Sql Postgresql
By using libpq on PG 9.1, I am trying to write query to get values from row with highest index 'my_id':
That gives me error:
ERROR: return and sql tuple descriptions are incompatible SQL state: 42601 Here is the test table definition. Create table reader_event ( reader_event_id serial, reader_name text, event_type varchar(25), event_date timestamp, metric_key text, metric_value bigint ) And here are the inserts. Insert into postgres SQL. Ask Question 0. Is there a way to insert a new record to a table which doesn't have an auto-increment ID without specifically entering the ID. INSERT INTO lists VALUES ((SELECT max(id)+1 FROM lists),'KO','SPH', '5'). Providing there's a key constraint on the id attribute, the worst that will happen is that one.
ERROR: aggregates not allowed in WHERE clause.. Pdf to jpg converter software serial key.
How to write such query properly?
a_horse_with_no_name![Select Max Serial Key Sql Postgres Select Max Serial Key Sql Postgres](/uploads/1/2/4/7/124726637/839897326.jpg)
329k5151 gold badges514514 silver badges608608 bronze badges
Wine TooWine Too2,1111717 gold badges6565 silver badges120120 bronze badges
5 Answers
If your goal is to get the row with the highest my_id value, then the following query should achieve the same goal.
GordonMGordonM23.1k1515 gold badges6363 silver badges117117 bronze badges
Just order by
my_id
and take only the first record with limit 1
Another but less performant way would be
![Serial Serial](/uploads/1/2/4/7/124726637/774915733.jpg)
166k2626 gold badges223223 silver badges284284 bronze badges
Muhammad HishamMuhammad Hisham
freedomn-mEdraw Max Serial Key
14.3k33 gold badges2424 silver badges5151 bronze badges
PSRPSR28.8k3232 gold badges9393 silver badges135135 bronze badges
when you have an index on my_id the ones with the subquery should be faster. when you dont have an index take the 'order by'. (obv. depends on database size if relevant)
Serial Key Finder
ChrisChris