@Scott Bailey suggested great idea. But it can be even simpler (you don’t have to create custom function) since PostgreSQL 9.5. Just use array_position
function:
ORDER BY array_position(array['Nails','Bolts','Washers','Screws','Staples','Nuts'], s.type)
More Related Contents:
- How does PostgreSQL perform ORDER BY with a b-tree index on the field?
- How to reset postgres’ primary key sequence when it falls out of sync?
- How to import CSV file data into a PostgreSQL table
- Calculating and saving space in PostgreSQL
- The forgotten assignment operator “=” and the commonplace “:=”
- Equivalent to unpivot() in PostgreSQL
- Passing user id to PostgreSQL triggers
- PostgreSQL: ERROR: 42601: a column definition list is required for functions returning “record”
- I forgot the password I entered during postgres installation
- Do nullable columns occupy additional space in PostgreSQL?
- How do I efficiently select the previous non-null value?
- How to configure PostgreSQL to accept all incoming connections
- Postgresql : Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections [duplicate]
- Dynamic SQL (EXECUTE) as condition for IF statement
- Disable PostgreSQL foreign key checks for migrations
- Prevent recursive trigger in PostgreSQL
- serial in postgres is being increased even though I added on conflict do nothing
- Can’t connect to Postgresql on port 5432
- PostgreSQL Error: Relation already exists
- How to make a select with array contains value clause in psql
- Using row_to_json() with nested joins
- Use variable set by psql meta-command inside of DO block
- Sorting array elements
- Postgresql query array of objects in JSONB field
- How to add a conditional unique index on PostgreSQL
- Select from a table variable
- Hashing a String to a Numeric Value in PostgreSQL
- Spring Docker container cannot access Postgres Docker container
- Format specifier for integer variables in format() for EXECUTE?
- PostgreSQL composite primary key