0

I am using the following query in pg-promise:

SELECT id, title, price 
FROM ${schema~}.ebooks
WHERE isbn = ${isbn};

pulling the data from pg with:

db.query(sql.ebooks.get, { isbn: isbn })

When I look at the row in pg they are in the order that I inserted them. The data does not have any ordering scheme (i cannot sort/order based on some column).

When using the query above, is it possible to get the data in the array to follow the row order in sequence?

M.Holmes
  • 403
  • 1
  • 7
  • 22
  • This isn't relevant to `pg-promise`, as the library doesn't order the records for you, the server does. And if you need it ordered in a certain way, you do need to specify an `ORDER BY` clause. – vitaly-t Jul 14 '17 at 01:45
  • so pulling data from pg using this library using the above query, it is assumed that the records in the array will not be in order in the way that if you just query the database via command line? If I query via command line the rows are in the order I inserted them. – M.Holmes Jul 14 '17 at 13:34
  • The order in which you inserted rows never guarantee to give the same back, that's not how SQL servers work. You must use `ORDER BY`. – vitaly-t Jul 14 '17 at 13:38
  • thank you. I did not know this. Greatly appreciate your time. – M.Holmes Jul 14 '17 at 13:44

0 Answers0