Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6623495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:32:22+00:00 2026-05-25T21:32:22+00:00

I have a table tips that is defined as follows: CREATE TABLE tips (

  • 0

I have a table tips that is defined as follows:

CREATE TABLE tips
(
  tip_id bigserial NOT NULL,
  tip text NOT NULL,
  author text NOT NULL,
  post_date bigint NOT NULL,
  likers character varying(16)[],
  dislikers character varying(16)[],
  likes integer NOT NULL,
  dislikes integer NOT NULL,
  abuse_history character varying(16)[]
);

I need to get the tips based on popularity, with the definition of popularity being:
likes – dislikes – (size(abuse_history)*5)

The query below gives me the same results regardless of the sort order (ASC/DESC).

select * from tips order by (likes - dislikes - (array_length(abuse_history,1) * 5)) ASC limit 2147483647 offset 0

EDIT

I inserted 3 records that have the following values:
1) 1 like, 0 dislikes, 0 abuse complaints
2) 0 likes, 1 dislike, 0 abuse complaints
3) 0 likes, 0 dislikes, 0 abuse…

Regardless of the sort order (ASC/DESC), I get the following order:
{3, 1, 2}

Could anyone please point me in the right direction?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:32:23+00:00Added an answer on May 25, 2026 at 9:32 pm

    Consider this:

    SELECT array_length('{}'::character varying(16)[], 1);  -- null
    

    Output is null for an empty array. Also, your abuse_history can be null itself. So you need something like this:

    SELECT tip_id
         , likes
         , dislikes
         , (likes - dislikes - COALESCE(array_upper(abuse_history,1) * 5,0)) as pop
         , (likes - dislikes - array_upper(abuse_history,1) * 5) AS fail_pop
    FROM   tips
    ORDER  BY pop DESC;
    

    fiddle

    Sample output:

     tip_id | likes | dislikes | pop | fail_pop
    --------+-------+----------+-----+----------
          1 |     1 |        0 |   1 |
          2 |     1 |        0 |   1 |
          4 |     0 |        0 |   0 |
          3 |     0 |        1 |  -1 |
          5 |     1 |        0 | -14 |      -14
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table with some fields that the value will be 1 0. This
I have table A in Oracle that has a primary key (id). I need
Hi I have written a function that is used to change text in a
I have a table that maintains rows of products that are for sale (
I have a mysql table (A) that's taking in hundreds to thousands of inserts
I have a project that creates a table from a DataTable to a SQL
I have an application that reads and writes to table in SQL Server 2005.
I have a table view with custom cells and I recognize swipes in that
I have a procedure ( procedureA ) that loops through a table and calls
I have a table message in a database that has almost a million rows.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.