You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
--only one recordcreatetableif not exists settings (
xpto decimalnot null,
xpto_alert_perc decimalnot null
);
createtableif not exists accounts (
account_id UUID default gen_random_uuid() primary key,
account VARCHAR(16),
active BOOLEAN DEFAULT TRUE NOT NULL,
unique (account)
);
CREATETABLEIF NOT EXISTS assets (
asset_id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
type VARCHAR(16) NOT NULL,
subtype VARCHAR(16) NOT NULL,
origin VARCHAR(32) NOT NULL,
asset VARCHAR(64) NOT NULL,
institution VARCHAR(54) NULL,
market_rate VARCHAR(16) NULL,
unit_price DOUBLE PRECISIONNULL,
matured_at TIMESTAMPNULL,
price_last DOUBLE PRECISION
);
createtableif not exists allocated_assets(
allocated_asset_id UUID default gen_random_uuid() primary key,
asset_id UUID not null,
account_id UUID not null,
market_position DOUBLE PRECISIONnot nullcheck (market_position >0),
lots DOUBLE PRECISIONnot null,
invested_amount DOUBLE PRECISION,
applicated_at TIMESTAMPnull,
lots_available DOUBLE PRECISION,
rentability DOUBLE PRECISION,
price_avg DOUBLE PRECISION,
foreign key (asset_id) references assets (asset_id) on delete cascade,
foreign key (account_id) references accounts (account_id) on delete cascade
);
createviewv_allocated_assetsasselecta.asset_id,
a.type,
a.subtype,
a.origin,
a.asset,
a.institution,
a.market_rate,
a.unit_price,
a.matured_at,
a.price_last,
a.description,
aa.allocated_asset_id,
aa.account_id,
c.account,
aa.market_position,
aa.lots,
CASE
WHEN a.type='stock' THEN
aa.lots*aa.price_avg
ELSE
aa.invested_amount
END invested_amount,
aa.applicated_at,
aa.lots_available,
CASE
WHEN a.type='stock' THEN
aa.rentability/100
ELSE
(aa.market_position/aa.invested_amount)-1
END as current_rentability_perc,
aa.price_avg,
CASE
WHEN a.matured_at IS NULLORa.matured_at>=CURRENT_DATE THEN TRUE
ELSE FALSE
END AS active,
CASE
WHEN a.matured_at IS NULL THEN NULL
WHEN a.matured_at<CURRENT_DATE THEN 'VENCIDO'
ELSE (extract(day from (a.matured_at-current_timestamp)))::TEXT
END AS valid_for
FROM assets a
inner join allocated_assets aa using (asset_id)
inner join accounts c using(account_id)
ORDER BY
CASE
WHEN a.matured_at>=CURRENT_DATE THEN 1
WHEN a.matured_at IS NULL THEN 2
ELSE 3
END,
CASE
WHEN a.matured_at>=CURRENT_DATE THEN a.matured_at
ELSE NULL
END ASC;
createviewv_xptoasselect account_id, account, institution, total_market_position,
( selectaa.market_positionfrom v_allocated_assets aa
whereaa.account_id=account_id andaa.institution= institution andaa.matured_at= next_matured_at
limit1
) as next_matured_value, next_matured_at,
EXTRACT(day from (next_matured_at-current_timestamp)) as next_matured_in,
s.xpto*s.xpto_alert_perc- total_market_position as free_to_invest,
greatest(total_market_position-xpto, 0) as not_covered_by_xpto,
least(total_market_position, xpto) as covered_by_xpto
from (
selectaa.account_id, aa.account, aa.institution, sum(aa.market_position) total_market_position,
min(aa.matured_at) as next_matured_at
from v_allocated_assets aa
group by account_id, account, institution
)
cross join settings s
order by next_matured_at, institution;
Version
1.27.0
What happened?
docker sqlc generate raise panic when I try to generate the code with a view that contains subquery and cross join on postgres.
I tried wrapper the select but does not works too.
Relevant log output
Database schema
Configuration
What operating system are you using?
Pop!_OS 22.04 LTS x86_64
What database engines are you using?
Postgres 16
What type of code are you generating?
Python code with this command:
docker run --rm -v "${PWD}:/src" -w /src/db sqlc/sqlc generate
The text was updated successfully, but these errors were encountered: