psql插入是否其他

发布于 2025-01-31 02:29:32 字数 573 浏览 3 评论 0原文

我想做到这一点,以便创建用户时,第一个用户在钱包上收到$ 1000,其余的 - $ 10(user_id -pk)

我提出了此请求

INSERT INTO users (user_id, login, balance, encrypted_password) 
select 1, 'login',
case
        when user_id = 1 then (login = 'login', balance= 1000, encrypted_password = 'password')
        else (login = 'login', balance = 10, encrypted_password = 'password')
end as user_id
RETURNING user_id

,但是当我提出此请求时,我会得到错误:错误:

错误:错误:列“ User_id”不存在 第4行:@user_id == 0时(登录='login',balance ='... ^ 提示:“用户”表中有一个“ user_id”列,但是从查询的这一部分无法引用它。

SQL状态:42703 角色:103

I want to make it so that when creating a user, the first user receives $ 1000 on the wallet, and the rest - $ 10 (user_id - pk)

I made this request

INSERT INTO users (user_id, login, balance, encrypted_password) 
select 1, 'login',
case
        when user_id = 1 then (login = 'login', balance= 1000, encrypted_password = 'password')
        else (login = 'login', balance = 10, encrypted_password = 'password')
end as user_id
RETURNING user_id

but when I make this request, I get the error:

ERROR: ERROR: column "user_id" does not exist
LINE 4: when @user_id == 0 then (login = 'login', balance= '...
^
HINT: There is a "user_id" column in the "users" table, but it cannot be referenced from this part of the query.

SQL state: 42703
character: 103

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文