Tagged Questions
1
vote
3answers
48 views
how to insert many records excluding some
I want to create a table with a subset of records from a master table.
for example, i have:
id name code
1 peter 73
2 carl 84
3 jack 73
I want to store peter and carl but not jack ...
0
votes
2answers
44 views
sql — issue with repeat values on join
I have two tables in PostgreSQL. I think it maybe due to an issue of my PK/FK or my lack of understanding of how to query properly:
CREATE TABLE Minute
(
Name varchar(20),
Day date,
Minute time,
...
-4
votes
1answer
31 views
Optimize postgres function [on hold]
Function code. Its works very slowly. How can I speed up
CREATE OR REPLACE FUNCTION bill."ReportIngredients"(
_from date,
_to date,
_beginning_date date,
_has_inventory boolean,
...
1
vote
2answers
29 views
Get field value from a record that causes an aggregate condition to be true
I have a table x which have the fields a, b, c, and d. I want to do a SELECT statement which is GROUPED BY a HAVING a_particular_value = ANY(array_agg(b)) and retrieves a, MIN(d), and c <- from ...
1
vote
3answers
41 views
Retrieve another field whose row is selected by an aggregate function
SELECT a.first_field, min(a.second_field), X
FROM a
GROUP BY (a.first_field)
I want X to be a.third_field which row is selected by min(a.second_field)
How do I do that?
Detailed explanation:
...
1
vote
1answer
26 views
Postgresql Treat array as records in a query
I want to treat array of timestamp as records that can be related with other tables.
For example
SELECT array[0], COUNT(b.id) FROM array, B WHERE B.date > array[0]
What's the best way to ...
0
votes
1answer
21 views
Filter table that I left join with
Here's my query
SELECT A.*
FROM A
LEFT JOIN B ON B.a_id = A.id
suppose there is a table C which relates directly to B, I want to filter out B based on C how do I do that? I've tried putting the ...
0
votes
1answer
74 views
Postgres Some sort of Joining?
I am pretty new to postgres and having troubles with something pretty difficult, which I need pretty badly. Additionally I am not working in a proper editor, it's some form of webbased editor. Please ...
-1
votes
1answer
42 views
'order by' in advanced recursive query with join on Postgres
I have problem with query, which based on recursive clause:
I have two tables: menu (menu categories) and menu_items (items in those categories). Those tables are join: each category can have some ...
1
vote
3answers
51 views
PG::Error: ERROR: operator does not exist: integer ~~ unknown
I'm making a search-function in a Rails project with Postgres as db.
Here's my code
def self.search(search)
if search
find(:all, :conditions => ["LOWER(name) LIKE LOWER(?) OR ...
1
vote
3answers
61 views
Detect range and count from a table
A table with 2 columns ordered by group, number:
group_id | number
---------+--------
1 | 101
1 | 102
1 | 103
1 | 106
2 | 104
2 | 105
2 | 107
...
0
votes
2answers
21 views
posgresql accessing the 1st element of the record
I have a function that returns a record type:
CREATE OR REPLACE FUNCTION
a()
RETURNS record AS '$lib/lib', 'a'
LANGUAGE C VOLATILE STRICT COST 1;
the function ...
0
votes
3answers
21 views
Show only table names when viewing postgresql tables
So I have no idea how to do this and I've been reading the documentation and searching around but I can't seem to find anything. \d gives me a nice list of all the tables and information on them but I ...
0
votes
4answers
71 views
SQL select values with or
Is it possible to make a query which does the following
select a,b or c,d from table where source=2 or target=2;
I want to select a,b if the source=2 or c,d if the target=2.
Is this possible ...
0
votes
2answers
43 views
SQL count more than 1 value accross multiple tables
I have a DB schema something like this:
CREATE TABLE projects (project_id int);
CREATE TABLE project_members (user_id int, project_id int);
CREATE TABLE project_issues (issue_id int, project_id int);
...