Tagged Questions
1
vote
3answers
26 views
Postgres selecting only columns that meet a condition
If I have a database table t1 that has the following data:
How can I select just those columns that contain the term "false"
a | b | c | d
------+-------+------+------
1 | 2 | ...
2
votes
1answer
30 views
Combining Multiple Columns from the Same Table Into 1 Longer Unique Column?
Data Source: http://www-01.sil.org/iso639-3/iso-639-3_20130520.tab
So I have a table like this (abbreviated from the actual table):
Part3 Part2B Part2T Part1 Scope Type Name Comment
...
-1
votes
0answers
26 views
select query in postgresql for display the data like target using source table [closed]
My Scneario is How to get this target table using query? Can anyone please help me in designing the query.
My source example is :
empno,ename,sal
1,aaaa,100
2,bbbb,200
3,cccc,300
3,cccc,400
My ...
0
votes
2answers
26 views
postgres query with current_date is not working
Below is my query in postgres
select dns_time,update_time from dns_lookup where update_time=current_date;
Here update_time is of type timestamp with time zone.
I have tried this one also.
select ...
1
vote
2answers
42 views
What is an Efficient Way to do an AND/OR Search Django-Postgres App?
In my Django app I have a Publication model and a Tag model which have a many to many relationship.
Let's say I have four tags: men, women, fashion, design. I want to find all publications that have ...
-3
votes
1answer
28 views
Is sysdate not supported in postgresql [closed]
I want to perform a query using sysdate like
"select up_time from exam where up_time like sysdate"
Is postgresql support sysdate.I did not find sysdate in postgres doc.Please help me
0
votes
0answers
17 views
Determination of the reasons of omission of request
There is a procedure reading from a database of value and writing data in ArrayLists which also register in files. As a result of program execution debug files are empty. Prompt in what business. As I ...
-2
votes
3answers
59 views
How to insert into table in Postgres?
INSERT INTO HMS_RESERVE_CANCEL_DTL
(DIVISION_CODE,
UNIT_CODE,
RESERVATION_NO,
RESERVATION_DATE,
CANCELLATION_NO,
CANCELLATION_DATE,
CANCELLED_AT_UNIT,
...
0
votes
2answers
43 views
postgresql index on string column
Say, I have a table ResidentInfo, and in this table I have unique constraints HomeAddress, which is VARCHAR type. For future query, I gonna add an index on this column.
The query will only have ...
1
vote
1answer
33 views
How to get distinct sums when summing over repeated values?
The issue I am having is with Postgres, in that using SUM with non-unique values or "sales" results in non-unique cumulative sums or "running sales".
Here is the query:
SELECT *,
SUM(Sales) ...
1
vote
3answers
43 views
How can I optimize this SQL query in Postgres?
I've got a pretty large table with nearly 1 million rows and some of the queries are taking a long time (over a minute).
Here is one that's giving me a particularly hard time...
EXPLAIN ANALYZE ...
0
votes
1answer
43 views
php variable in query - postgresql
I have problem with query value.
This is working.
$userArray = $database->select("app", "fb_id=14175962160");
but this isn't working. WHY?
$user = $facebook->getUser(); // contains my fb id ...
1
vote
3answers
78 views
Quite a tricky SQL query
I have the table EMPLOYEE with 3 fields:
EMPLOYEE(ROLE SMALLINT, RATING INTEGER, NAME VARCHAR)
I need get from this table only 3 row. It's One row of each type with the highest rating in its type. ...
-1
votes
1answer
44 views
Postgresql Dynamic SQL Query [closed]
I need create this query dynamically:
INSERT INTO "calle" (a, b, c, d)
SELECT l.id_localidad, v.tipovial, v.nomvial, v.geom
FROM "010010001v" AS v,
dblink('dbname=xxx port=xxxx host=xxxxx user=xxx ...
0
votes
1answer
28 views
How to split value with new line in Postgres?
I had a table name BookInfo
id / book_name / description
1 / book 1 / harry
potter
Part 2
How can I split between new line (harry \n potter \n Part 2 ) ...
3
votes
2answers
41 views
How to detect if value have new line \n in Postgres
Example I have table name: bookInfo
values
id / book_name / description
1 / book 1 / dummy
2 / book 2 / harry
potter
Part 2
In id 2 description have a newline ...
0
votes
4answers
53 views
SQL WITH clause doesn't work
I'm trying to execute seemingly simple request contains WITH clause:
WITH sub AS (SELECT url FROM site WHERE id = 15)
SELECT * FROM search_result WHERE url = sub.url
But it doesn't work. I get
...
1
vote
3answers
66 views
PostgreSQL Select from 5 million rows table
I have table with about 5 million rows
CREATE TABLE audit_log
(
event_time timestamp with time zone NOT NULL DEFAULT now(),
action smallint, -- 1:modify, 2:create, 3:delete, 4:security, 9:other
...
0
votes
1answer
34 views
Joining two table by mask
I have 2 tables PAGE and SITE. PAGE table has field URL. And SITE table has field DOMEN_URL. I want to join two tables on these fields. But I want to condition of joining is that url of the page ...
0
votes
1answer
55 views
SQL query: how do results get retrieved via “any” in own columns?
Another SQL question. I have the following query:
SELECT EXTRACT(epoch from dt) as diff
from (
SELECT time_col - lag(time_col) OVER dt
FROM myTable where elementID=1234
) as dt
This ...
3
votes
3answers
97 views
Selecting 10% random number from a infinite stream
There is a stream of numbers coming. At any point of time i might need 10% random numbers.
I obviously don't want to store the entire stream.
The bigger problem is for which i am thinking the above ...
2
votes
2answers
55 views
String seems to end query
I am storing user's liked pages from facebook in my postgres database, one of them being Sinead O'Connor's page. It seems like when it gets to the apostrophe, it terminates the query beacuse the ...
0
votes
2answers
59 views
The sample from the database by date using only the day and month. Not taking into account the year [duplicate]
I have a database, let's call it "mydb".
The database "mydb", there is a table "mytable".
In the table "mytable", three fields: text (type char), start_date (type DATE) and end_date (type DATE).
I ...
0
votes
1answer
39 views
Performance Impact of turning Columns into Rows
I'm planning to use JavaDB (Derby) or PostgreSQL.
I have the following problem: I need to store a large set of vectors. Currently all vectors contain a fixed number of elements. Hence the appropriate ...
0
votes
2answers
41 views
PostgreSQL: Get the second to last MAX(date)
I have two views in PostgreSQL. One to get the most recent total amounts of each organization. The other view is to get the second to last most recent total amounts of each organization and here is ...
1
vote
3answers
49 views
Join mutiple tables with date
I have three tables
**Table A**
+-----------------+
| Name | ID |
+------------------
| A1 | 1 |
| A2 | 2 |
| A3 | 3 |
+------------------
**Table B** ...
0
votes
1answer
36 views
Creating a view SQL
These are the tables I have to work with.
customer (cust_id, name, city, postcode)
order (order_id, cust_id, date)
orderline (order_id, video_id, quantity)
video (video_id, description, price, ...
1
vote
2answers
37 views
Formulating an SQL statement
I need help formulating an SQL statement.The tables are
video(video_id, description, price, category_id)
category(category_id, description)
The query needs to produce a summary list showing the ...
1
vote
2answers
47 views
SQL Union without duplicate values for one specific field
There're 3 tables DEVELOPER, MANAGER and PROJECT:
create table DEVELOPER(id int(4), lastname varchar(40), project_id int(4));
create table MANAGER(id int(4), lastname varchar(40), project_id ...
0
votes
1answer
35 views
“ProgrammingError: syntax error at or near” when executing query in python using psycopg2
I am running Python v 2.7 and psycopg2 v 2.5
I have a postgresql database function that returns a sql query as a text field.
I am using the following code to call the function and extract the query ...
0
votes
3answers
77 views
How can I select one row of data per hour, from a table of time stamps?
Excuse me if this is confusing, as I am not very familiar with postgresql. I have a postgres database with a table full of "sites". Each site reports about once an hour, and when it reports, it makes ...
0
votes
2answers
23 views
Append X amount of results from one query to X amount of results from another (with no foreign key join)
This query brings back results like this: select distinct date from dwh.product_count
April, 2013
March, 2013
February, 2013
January, 2013
I'd like to append however many results ^that^ brings back ...
1
vote
1answer
41 views
Convert a nested subquery into normal query
I have problem with following query where in which the nested query should be
converted to normal query:
select
count(*) as count,
TO_CHAR(RH.updated_datetime,'DD-MM-YYYY HH:MI:SS') as date,
...
1
vote
3answers
81 views
Improving Subquery performance in Postgres
I have these two tables in my database
Student Table Student Semester Table
| Column : Type | | Column : Type |
|------------|----------| ...
0
votes
2answers
25 views
How to store the results in table?
I have a one table A and that contains values
NAME AGE
Loga 18
Anitha 20
Saranya 13
I was test the table values like if condition using case statement case when AGE>=18 then 'major'
...
2
votes
6answers
96 views
How to write the following query correctly?
Find all bars that sell beers that are cheaper than all beers sold by "99 bottles"
EDIT:
Interpretation:
So compare all the beers from Bar1 and check if all the those beers are cheaper than "99 ...
0
votes
1answer
63 views
No value specified for parameter 1
I am using Hiberante to connect to postgres database. I am trying to insert a record into the database. I have the values for the record in a string array which I got from a csv file. This is my dao ...
0
votes
3answers
62 views
Debugging a SQL Query
I have a table structure like below. I need to select the row where User_Id =100 and User_sub_id = 1 and time_used = minimum of all and where Timestamp the highest. The output of my query should ...
1
vote
1answer
45 views
SQL window functions: Performance impact of returning the same avg() many times?
I would like to SELECT a bunch of rows from table A, along with the results of aggregate functions like avg(A.price) and avg(A.distance).
Now, the SELECT query takes a good bit of time, so I don't ...
-3
votes
2answers
42 views
PHP (mysql) => Django (postgresql) [closed]
Please help me remake sql query from PHP to Django (PostgreSQL):
$sql = 'SELECT `posts`.`entityId`, `posts`.`listId`, `posts`.`message`, `posts`.`time` FROM `subscriptions`, `posts` WHERE ...
0
votes
2answers
42 views
How to select rows where a combination of 2 columns is the same
Sorry that the title is so bad, I'll try explaining with a simplified example:
lets say I have the following table:
_______________________
|id|variant_id|attr_id|
|__|__________|_______|
|1 |15 ...
0
votes
2answers
34 views
Checking which radio button is selected in php
I have an html page that has two radio buttons ("yes" and "no") along with a submit button.
How can I specify that I want to execute a posgresql query only if the submit button is pressed AND the ...
1
vote
2answers
39 views
new to php, what's wrong with my sql query?
I'm trying to run a query using php and its posgresql built in functions but I can't figure out why my sql query isn't being run. Can anyone point out to me what's wrong with this:
// create our ...
1
vote
3answers
70 views
Get rows where two values are unique to each other
The values of interest are an EIN and a registration number REG.
There are lots of records for each value.
What I want to know is which pair of values only appears with each other (or a blank EIN).
...
0
votes
1answer
38 views
Showing specific output data based on duplicate rows and null values [postgresql]
I'm using the following SQL (with a union to two similar queries):
SELECT
distinct a.source,
a.p_id,
a.name,
b.prod_count,
b.prod_amt,
'Def' as prod_type
FROM
...
1
vote
2answers
25 views
Filtering a many to many (PostgreSQL)
create table "users"(
"id" SERIAL PRIMARY KEY NOT NULL,
"full_name" varchar(100) NOT NULL,
"role" integer NOT NULL DEFAULT 0,
"email" varchar(100) NOT NULL
);
create table ...
0
votes
3answers
60 views
finding the latest entry in Postgres
The following (Postgres) query always returns a result, because the performance.query_plan table has several entries, with different ts (Timestamp) values.
select * from
performance.query q,
...
0
votes
1answer
41 views
Is it posible to create a timestamp with meridian indicator in postgres?
I'm trying to create a timestamp column like
"20-04-2013 06:56:37 AM"
I can use to_char function to create it as a text. But it impossible with a timestamp column.
4
votes
3answers
75 views
How do I limit a select by a sum?
I want to select all the cheapest toys of my stock, amounting a total of 10.0 USD:
That is, I want to do something that looks like this:
select * from toy where sum(price) < 10.0 order by price;
...
4
votes
2answers
1k views
Find Parent Recursively using Query
I am using postgresql. I have the table as like below
parent_id child_id
----------------------
101 102
103 104
104 105
105 106
I want to write a sql query which will ...